Javascript help


#1

Hi can anyone tell me whats wrong with my syntax?

// Check if the user is ready to play!
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
confirm("I understand confirm!");
var age = prompt;
var userAnswer = prompt;
prompt ("What's your age?");
if(age < 13)
{
console.log("You can play but I take no responsibility");
}
else
{
console.log("Play on dude");
}
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");

prompt("Do you want to race Bieber on stage?);


#2

At a quick glance it looks like you just forgot the closing quotes in your last line.


#3

Thanks that was it.

Heres another one. Can you please tell me whats wrong?

// Check if the user is ready to play!
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
confirm("I understand confirm!");
var age = prompt;
prompt ("What's your age?");
if(age < 13)
{
console.log("You can play but I take no responsibility");
}
else
{
console.log("Play on dude");
}

console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt;
prompt ("Do you want to race Bieber on stage?");

if(userAnswer = "yes");
{
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}


#4

Oh, sorry..didn't see your second question before:

Your if-statement is a bit wrong, should be:

if(userAnswer == "yes")
{
[.. ..]
}

You need == to compare, because a single = just sets a variable to a value and so on. And in addition you put a semicolon after the if-parentheses. This ends the statement. Your if did this:

if( true ) { };

After that the else didn't know where it belonged to, because the if was done by that point.


#5

Thanks a lot man. It was very helpful.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.