Lesson 5


#1



https://www.codecademy.com/courses/javascript-beginner-en-x9DnD/0/5?curriculum_id=506324b3a7dffd00020bf661


Hi, i'm really not looking for help like copy and paste the solution, but just for an exlication why the code i wrote doesn't work if i've follwed all the istructions. thank you.


// Check if the user is ready to play!
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.'");
}


#2

Are you sure you're not missing a semicolon somewhere?


#3

Hi biff75,
1 of all, thank you very much 4 ur answer.
Actually i try to put semicolons even when they are not needed.
I'm very new in javascript language and an intermediate in VBA, so errors comes easely.
As i've learnt in the previous lessons and from examples, the semicolon is not needed at the beginn, in the middlel and at the end one's if statemen. After a prompt i've never put one.
This is the reason why i've wrote, i've also tryed to reset the code and write it again, no success.

Maybe you other someone else have a better idea why?

Thks


#4

Maybe if you post the entire code something will become more obvious.


#5

Hi Biff75, here we go with me "wrong code", thks 4 ur help or any suggestion.
Very strange it doesn't reconize the if statement but in the console comes out differents answers dependig if i say yes to the prompt or not...

// Check if the user is ready to play!
confirm("I'm ready to play!")
var age = prompt("What's your age");
if(age < 13){
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.'");
}

and this is what come out as error:

Oops, try again. Did you add an else statement to your code?

Thank you


#6

In this part, you have no else code written for what to run if the user enters an age over 13.


#7

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