I am trying to determine what the total is equal to and then do a job pertaining to each selection. My first selection is if the total is 2, 3, or 12, then you lose. If it is a 7 or a 11, you lose. Anything else the point is established. First my code looked like this, but every single time, it went to else. The total is being calculated through 2 random numbers added together using this function:
Math.floor(Math.random()*6+1);
function game()
{
if(total==2 || total==3 || total==12)
{
alert("You lose. Please start a New Round");
}
if(total==7 || total==11)
{
var temp= 2 * bet;
alert("You win $" + temp);
}
else
{
alert("Point Established. Roll again.");
var point=total;
setTimeout(rolldice2,3000);
}
}
Then I changed it to this:
function game()
{
if(total==2 , 3 , 12)
{
alert("You lose. Please start a New Round");
return;
}
if(total==7 , 11)
{
var temp= 2 * bet;
alert("You win $" + temp);
return;
}
else
{
alert("Point Established. Roll again.");
var point=total;
setTimeout(rolldice2,3000);
}
}
But it just says you lose no matter what. Then I finally took out return. It does the first 2 and not else. I want to be able to choose one- depending on what the variable total is equal to- and then perform its jobs and then leave the function.
In your case
totalvariable isundefinedPass
totalto your function and do aswitchstatement