![]() |
Javascript Help please!!
Hey all! I am having some trouble with my program for blackjack; my variables a,b,c and d will not store values from randomCard ( I use them later in the code to print out a card image on the screen). Does anyone see anything I might be overlooking? (randomCard DOES get a value from Deal(), which is a random number generator, I know this because randomC() utilizes randomCard).
Thanks for your time! Code:
|
I am putting the variables in the code shown below, if I enter a [0] or [1] the correct image shows up, but I need it to coincide with the the random variable instead of 0 and 1.
Code:
<form NAME="form"> |
This makes NO SENSE at all:
Code:
randomCard = Deal();Why didn't you simply code a = Deal();?But then you set player[0] to the result of calling the function randomC()! WHY??? *APPARENTLY* you have a Deal( ) function that returns one random card. That's great. But then why do you have *ANOTHER* function randomC() that does the same thing???? On top of that, you get the score for the player by adding player[0] and player[1]. But why in the world would *THAT* score match the sum of the values of a and b??? Except by the wildest coincidence? ********* In your second post, you show this: Code:
document.write('<img alt="random image" src="' + playerC[a] + '"/>');Where did *THAT* come from? In the prior code, you had player[0] and player[1], but you certainly didn't have any playerC[ ]. On top of everything else, document.write is badly obsolete and you should *NOT* be using it. |
Deal() returns a value 0-51.
randomC() takes the RANDOMCARD and assigns it a card VALUE based on a case switch statement. playerC[] are the cards, I have an array set up with 0-51 assigning a different card in the deck. a & randomCard must be equal numbers so I assign the correct card, that is why I do not simply code a = Deal(). If document.write is so obsolete why not inform me of the appropriate code? Thank you, I think. |
Okay...begins to make more sense.
Your playerC is fine, though I would have used a more descriptive name. After all, you use those images for the dealer's cards, as well. Maybe cardImage[ ]? But that's quibbling. Quote:
I would have written it as Code:
function cardValue( card )If you were going to do that, you could have had Deal( ) set a global variable with the card's value. But even that is bad design. ********* In place of document.write, you should use DOM methods. For example: Code:
<td><img id="PC1" alt="player card 1"/></td> |
By the by, there is no need for a switch( ) in your cardValue( ) function (what you were calling playerC( ).
Assuming that 0-12 are the Ace through King of Clubs, 13-25 are Ace through King of Diamonds, etc.: Code:
function cardValue( card ) |
Oh...and named <form>s are also obsolete. Give the form an ID, instead, and then use
Code:
var form = document.getElementById("theForm"); |
Thank you so very much for your help! This cleared up a lot and I have the images showing with appropriate values. :thumbsup:
|
| All times are GMT +1. The time now is 03:52 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.