HighDots Forums  

Re: Help Needed!!!

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Help Needed!!! in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Help Needed!!! - 10-21-2003 , 10:02 AM






"D o t A u" <spam69 (AT) tpg (DOT) com.au> wrote

Quote:
I have run into a brick wall with a syntax error ...
snip

If it was a syntax error you would have an error message with a line
number.

Quote:
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

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.

Quote:
// 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.

Richard.




Reply With Quote
  #2  
Old   
D o t A u
 
Posts: n/a

Default Re: Help Needed!!! - 10-21-2003 , 11:05 PM







"Richard Cornford" <Richard (AT) litotes (DOT) demon.co.uk> wrote

Quote:
"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.
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.

Quote:
// 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.
Yeah, I know, but for this game it's fine and it's what everyone in the
class in using.

Cheers















Reply With Quote
  #3  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Help Needed!!! - 10-22-2003 , 10:50 AM



"D o t A u" <spam69 (AT) tpg (DOT) com.au> wrote

Quote:
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.
Quite the reverse, it makes more sense for a student to rigorously
impose formal structure on their source code and leave it to experience
to inform them when it is appropriate to abandon it.

Quote:
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.
Sheep. The method is wrong and it would not take much research to find a
correct version. And if a gambling game is going to be biased the user
should not be in a position to find out and exploit it, the bias should
favour the house only.

Richard.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.