Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-23-2012, 02:36 AM   PM User | #1
KashSmith100001
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
KashSmith100001 is an unknown quantity at this point
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
KashSmith100001 is offline   Reply With Quote
Old 12-23-2012, 02:45 AM   PM User | #2
KashSmith100001
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
KashSmith100001 is an unknown quantity at this point
I did do some research to get to this point, but I'm stumped now.
KashSmith100001 is offline   Reply With Quote
Old 12-23-2012, 02:52 AM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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?
xelawho is offline   Reply With Quote
Old 12-23-2012, 02:53 AM   PM User | #4
KashSmith100001
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
KashSmith100001 is an unknown quantity at this point
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.
KashSmith100001 is offline   Reply With Quote
Old 12-23-2012, 02:54 AM   PM User | #5
KashSmith100001
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
KashSmith100001 is an unknown quantity at this point
Ok - it works now, I'm so sorry man, I feel like an idiot, but thanks for the help.
KashSmith100001 is offline   Reply With Quote
Old 12-23-2012, 03:05 AM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:35 AM.


Advertisement
Log in to turn off these ads.