View Full Version : Does it matter what value we give the bet?

05-24-2012, 08:56 PM
function rollthedice() //



alert ("Play til you lose it all");

while (money>=1)


//no betting more money than you have!

//the line below will go forever...the if...break will

//get you out of this infinite betting loop if you bet legally

while (1==1)


pick=window.prompt("Please pick over 14(o) or under 14(u)","u");

bet=parseInt(window.prompt("Please bet",money)); //
if (bet<=money && bet>0) break; //

alert("Illegal Betting detected!");





//the *6 gives you 6 numbers and the 1 says start at 1 so

//we randomly get numbers between 1 and 6 like on a die


document.write("</br>You rolled "+die1+" and "+die2+" and "+die3+" and "+die4+" total = "+total);

document.write("</br>You picked "+pick+" and rolled "+total);

//you win if you pick u and you get less than 14

//OR you pick o and you have more than 14

if ((pick=="u" && total<14) || (pick=="o" && total>14))



document.write(" You won! You now have $"+money);


else if (total==14)


document.write(" 14 is a tie...no winner..keep your bet");




document.write(" You Lost! You now have $"+money);

} //end of the if statement

} //end of the---lets play WHILE we have more than $1 left

alert ("Thanks for giving me all of your money!");

} //end of the function


Philip M
05-25-2012, 08:15 AM
No. It should really read var bet; (Note the use of the var keyword which you have omitted throughout).

Prompt is a very primitive way to obtain user input. Alerts should be used only for debugging.

As has been explained a zillion times in this forum, document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

In short, you are being taught to write antiquated and long-obsolete code! ;) There are many other problems with your code, particularly the absence of any input verification.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Philip M
05-25-2012, 09:09 AM
The great advantage of being on iBall's ignore list is that, although many of his posts simply repeat what has already been said, he cannot seize on something in one of my posts to start a pointless and belligerent argument. :p