Jump to content
Stef's Coding Community
Sign in to follow this  
benjaminmorgan

Start of a blackjack Game. Javascript Problem.

Recommended Posts

My site is at http://blackjack.web44.net/blackjack and I am trying to make it where the numbers add together correctly but I can't get the numbers to add when I click the hit button it doesn't add the 3,4, or 5 number to the current score which is assigned in the variable yosco in deal function. I am trying to make it where it adds number 3 in the 1st hit function and if they hit again it adds all of the numbers plus number 4 then the same with 5.

Edited by benjaminmorgan

Share this post


Link to post
Share on other sites

Personally, I would approach dealing with this by adding console.log() statements that track when functions are being called and what the values of the various variables you are using are. I would start by checking to make sure functions are being called when you expect them to, and that the variables you are using hold the values that you expect them to.

 

In all of your hit() functions, I'm not seeing any code that actually updates the number that displays on the screen. I'm seeing a "yosco" variable that gets added to, but I'm not seeing that variable used to update the "Your cards equal: X" text.

Share this post


Link to post
Share on other sites

When I add this it doesn't work still. It should update it with the new yosco variable after the hit button is correct. The function is being called because the card is dislaying.

	
yosco = num1 + num2 + number3;
yougot.innerHTML = "Your cards equal: " + yosco;

 

Well now it appears to be working, guess I had to clear my cache. Thanks Ben. Happy Independence Day.

Edited by benjaminmorgan

Share this post


Link to post
Share on other sites

Grr, Another problem. :bash: Now I can't hide the hit button when someone busts. If they keep hitting hit it makes them lose 10 points until the button is unclickable. I have tried to hide the hit buttons in the code but none seem to work. Apart from that the adding and busting is working right. Also if you click the deal button after you bust and there is still a hit button showing 2 of them will show up after you click deal. The 2 buttons call a different function.

Edited by benjaminmorgan

Share this post


Link to post
Share on other sites

firefox doesn't seem to work at all. Grr. It seems to work in every other browser! Well not the hiding part but the changing cards and hit buttons. Firefox doesn't add the card either.

Edited by benjaminmorgan

Share this post


Link to post
Share on other sites

To get it to work in Firefox, you need to clean up the errors:

 

-- use of undeclared variable num3

-- use of undeclared variable num4

-- yougot not defined (it's only defined within deal() but due to variable scope, it isn't accessible within the hit() functions)

 

You need to watch the Javascript console for errors, and deal with anything that pops up.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...