Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I get the error: "Syntax Error - Unexpected Token"

    I was hoping someone could help me figure this out, I'm new to JS.

    Here is the code:

    <html>
    <title>Hustle - FWB</title>
    <body>
    <h1>Hustle</h1>
    <form name = frmMain>
    <input type = button value = "Roulette" name = cmdRoulette OnClick = roulette();>
    </form>
    <script language = javascript>
    var money = 20;


    function roulette() {

    if (money < 6) {
    alert("You don't have enough money to play!");
    return;
    }

    choice = prompt("Red or Black?);

    var x=Math.floor(Math.random()*11) + 1;

    if (x < 6) {
    alert("You win $10");
    money = money + 10;
    }
    else {
    alert("You lose $5");
    }

    }


    </script>
    </body>
    </html>

    Thanks for any help you can provide,
    Kris

  • #2
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did do some research to get to this point, but I'm stumped now.

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,910
    Thanks
    56
    Thanked 544 Times in 541 Posts
    in my error console (Chrome) it says "Uncaught SyntaxError: Unexpected token ILLEGAL" and points to line 19, which is this one:

    Code:
    choice = prompt("Red or Black?);
    surely you can see the problem there?

  • #4
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    in my error console (Chrome) it says "Uncaught SyntaxError: Unexpected token ILLEGAL" and points to line 19, which is this one:

    Code:
    choice = prompt("Red or Black?);
    surely you can see the problem there?
    Ok, it's official - I'm an idiot, let me try and remedy that and see if it works, I apologize.

  • #5
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok - it works now, I'm so sorry man, I feel like an idiot, but thanks for the help.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,910
    Thanks
    56
    Thanked 544 Times in 541 Posts
    hey, no - it's not about being an idiot, it's about learning to read your error console, which is your number 1 tool if things go wrong. If you learn to use it properly (which an astonishing amount of coders don't) it will save you much time and many questions here... it's one of those boring "give a man a fish... " type of deals


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •