Reputation: 291
I am creating a Java Script/ HTML crapps game. I had the game working as you would roll a dice, it would tell you if you won, point was created, or lost. Obviously this game is not completed. I want to add code where it creates your point, then rolls the dice again until either point reached or 7 rolled. Here is my current code:
function game()
{
if(point==4,5,6,8,9,10)
{
if(total==point)
{
if(total==6,8)
{
var temp= 2.2 * bet;
alert("You win $" + temp);
}
if(total==5,9)
{
var temp= 2.5 * bet;
alert("You win $" + temp);
}
if(total==4,10)
{
var temp= 3 * bet;
alert("You win $" + temp);
}
}
if(total==7)
{
alert("You lose. Please start a New Round");
}
else
{
setTimeout(rolldice(),3000);
}
}
if(total== 2,3,12)
{
alert("You lose. Please start a New Round");
}
if(total==4,5,6,8,9,10)
{
alert("Point Established. Roll again.");
var point=total;
setTimeout(rolldice(),3000);
}
if(total==7,11)
{
var temp= 2 * bet;
alert("You win $" + temp);
}
}
The function before this rolls the dice ans is called rolldice(). That function works as it rolls the dice and displays pictures as I like it. If I mentally go through the script, I cant see any errors. I went through all my bases- 2-12. What I do not know is if the first selection throws off function. At this point in the file, the point has not been created. Yet it needs to go first because if it goes through it a second time, it needs to go there. At first, I thought I was not calling this action. But I added an alert in the first line of the function and when I triggered this function the alert occurred. That tells me there is something wrong with my function. I went into Google Chrome's console and it says there is an error called, "uncaught rangeerror maximum call stack" at line 130 which is at
if(total==7)......alert("You loose")
When I googled this, I found lots of stuff but as I am inexperienced and just typing it out not using jquery, I am a little confused.
Upvotes: 0
Views: 114
Reputation: 1920
You should change expressions like:
if(total==5,9)
to something like this:
if(total==5 || total==9)
if you mean OR in your logic.
Upvotes: 1