![]() | |
#1
| |||
| |||
|
|
I have run into a brick wall with a syntax error ... snip |
|
var bet_in = 0 snip function bet(bet_in) { if ( bet_in == 1 ) { bet_out = "1 to 4" } else { if ( bet_in == 2 ) { bet_out = "5 to 8" } else { bet_out = "9 to 12" } } if ( pick_clickcount == 0 && dep_clickcount == 1 && gamble_clickcount >= 1 ) { alert("You Picked " + bet_out) pick_clickcount++ } else { if ( dep_clickcount == 0 ) { alert("You must deposit money first") } else { if ( gamble_clickcount == 0 ) { alert("You must bet first") } else { alert("You have already picked") } } } } snip |
|
// Get Random Number For Dice function get_random() { var ranNum= Math.round(Math.random()*11); return ranNum; } snip |
#2
| |||
| |||
|
|
"D o t A u" <spam69 (AT) tpg (DOT) com.au> wrote in message news:bn4d23.3lc.1 (AT) Fake (DOT) net... The main problem is that you have used the parameter name "bet_in" in the - bet - function and also used the same name for a global variable that is tested in the - roll - function. It looks like you expect the - bet - function to be setting the global variable "bet_in" but the - bet - function does not do that and the global "bet_in" just retains its default value of zero. So when it is tested in the - roll - function the user always appears to have lost. Apart from that you are suffering from the effect of not imposing any discipline on the structure of the code that you write. The result is an unintelligible mush that is hard to follow and (self evidently) hard to debug. Probably the biggest favour you can do yourself is to identify a style of consistent block indenting, adopt it and rigidly stick to it. |
|
// Get Random Number For Dice function get_random() { var ranNum= Math.round(Math.random()*11); return ranNum; } snip You also need to look at your random number generator, it is biased. |
#3
| |||
| |||
|
|
The main problem is that you have used the parameter name "bet_in" in the - bet - function and also used the same name for a global variable that is tested in the - roll - function. ... snip ... . Probably the biggest favour you can do yourself is to identify a style of consistent block indenting, adopt it and rigidly stick to it. Hey, that was really simple, thanx a million.. I know the code is messy for you, but I think it's not bad for a beginner. |
|
function get_random() { var ranNum= Math.round(Math.random()*11); return ranNum; } You also need to look at your random number generator, it is biased. Yeah, I know, but for this game it's fine and it's what everyone in the class in using. |
![]() |
| Thread Tools | |
| Display Modes | |
| |