5: The story heats up!


#1

So i keep getting this error "SyntaxError : Unexpected Token Else" and i don't know what i have done wrong
Code:
var ready = confirm("Ready?")
var age = prompt("Annnd...How old are you?")
if(age <13)
{
console.log("Don't play this game!")
}
else
{
console.log("Now we will begin the story!");
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = 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.'");
}
Someone knows what's up?


#2
if(userAnswer === "Yes"); //<<< NO Semicolon

#3

But then it says: SyntaxError: Unexpected end of input


#4

var ready = confirm("Ready?");
var age = prompt("Annnd...How old are you?");
if(age <13){

    console.log("Don't play this game!");

}else
{

    console.log("Now we will begin the story!");

    console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

    console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");

}


    var userAnswer = 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.'");
    }

u missed one of" }" .. and there is ";" after else ,


#5
var age = prompt("Annnd...How old are you?") // Because there is NO Semicolon

#6


#7

Thank you sooooooooo much I could not get mine to work for like a week and Codecademy would not email me back! Also it was crazy! I copy/pasted yours and it worked even though mine should have and then I get to the next lesson and MY code comes up and when I add the next thing THEN mine works. What a waste of me trying to fix my code for a week.


#8

:grinning: you are welcome!!! you can ask me anytime as long as i know ,i will help you ..lets learn it together .


#9

Hi, I have a problem with this step...

After save & summit code, appears the error: Oops, try again. Did you add an if statement to your code?

Here is my code:

console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");

var userAnswer = 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.'");
}


#10

Hey jerry_89, I copied yours and it finally works. But it was really weird because on the next lesson it had my code and not your copied one. So I added the next thing, Save and Submit, and mine WORKED! But on the lesson before it did not work. So if there is something wrong please tell me. Here is the code:

// Check if the user is ready to play!
confirm("Are you ready to play?");
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = 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.'")
}
Thanks CBStockdale


#11

DUDE I don't understand, I thought 3 = signs means equal to, yet your solution only uses 2 and it works. headache..


#12

Keeps asking me if I remembered to add an "if" statement... not sure where the hang up is?

confirm("Are you ready to play?");
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = 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.'")
}


#13

The difference between the "==" and "===" is best described as "equality without type coercion" by the differences bellow:

'1' == true; //true because the type doesn't matter.
'1' === true; //false because now the type of variable matters!
0 == false; //true 
0 === false; //false 
1 == '1'; //true
1 === '1'; //false

strings, integers, Booleans, and Objects when being equaled with three '=' signs, need to have the same type of equality. Meaning strings can only === strings, integers can only equal integers, and so on.

With a '==' only the value between the two things you're comparing has any merit to the equation.

sited from stackoverflow.com


#14

I believe your problem is:

if(userAnswer = "yes")

As with my last post, notice that the '=' sign makes a big difference in how you do it. Right now you are assigning "yes" to userAnswer. And you can't just do that in an if statement. change that to '===' and see if that works.


#15

Here is a screen shot of the code...


#16

var userName = ("Mike")
confirm(userName + " are you ready to play?");
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = 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.'")
}

---- ERROR is Oops, try again. Did you add an if statement to your code?-----


#17

Could you just add the screenshot to the forum? I get the chills when there's a link in any forums #hacksforlife


#18

just pasted it in... including the exact syntax of the error message i'm receiving.


#19

Oh I think you're missing the first if statement you're suppose to have.

var ready = confirm("Ready?");
 var age = prompt("Annnd...How old are you?");
 if(age <13){
    console.log("Don't play this game!");

}else
{

    console.log("Now we will begin the story!");

    console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

    console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");

}

quoted from @jerry_89.

I'm fairly certain this code is suppose to stay throughout the lessons. If you deleted this, I'd suggest resetting your code and then doing the lesson over again to make sure you don't miss anything.


#20

That's exactly what I did, I cleared the screen each time... here is the WORKING code for step 5....

var userName = ("Mike")
confirm(userName + " are you ready to play?");
var age = prompt("What's your age?");
if(age <= 13)
{
console.log("You must be 21 or older")
}
else
{
console.log("Game on!")
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = 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.'");
}