0

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.

4
  • Can you show us newGame? Commented Feb 1, 2013 at 2:27
  • Didnt create code for it yet. When I take all of the newGame out, the same thing happens- which is nothing. None of the alerts come up, and I do not know if point was established, etc. Commented Feb 1, 2013 at 2:40
  • if(point==4,5,6,8,9,10) doens't seem to be a valid syntax, also for other similar statements. Commented Feb 1, 2013 at 3:05
  • @AlvinWong I fixed that by following hamilton.lima's suggestion and it looks like that fixed one of the problems. But the functions syntax is still not working. As you said, the syntax is messed up. That is what I have to figure out. Commented Feb 1, 2013 at 4:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I did what you said for everything (changing variable names of course). It still does not work. However, when I check console in Google Chrome, the error does not show up. So it helps a little bit, yet there is still an underlying problem. Probably a syntax error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.