CodeAcademy Console can't find "else-statement" in 5th chapter


#1

Given SourceCode (see below in code-section)
And Chapter 5. The Story heats up
When I try to execute the SourceCode
Then I get the error message Oops, try again. Did you add an else statement to your code?

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

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

var userQuestion = "Do you want to race Bieber on stage?";
var userAnswer = prompt(userQuestion);

//if (prompt("Do you want to race Bieber on stage?") === "yes") {
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.'");
}

As you can see in the sourcecode i tried to make it work on two ways - the commented version does not work and the nicer version with the variable is also not working. i do not see any misspellings or so.


#2

I already found a solution that isn't nice. And i don't understand whats the problem with the code above.

if (userAnswer === true){
userAnswer = "yes"
}
else{
userAnswer = "no"
}
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.'")
}

Is that really the real solution?

nohates #justdiscussit


#3

no, not really. The exercise checks if you have two if/else clauses, you should have the age prompt from chapter 2 (old enough to play) and the if/else clause you add in this exercise (chapter 5)


#4

I see. thats a good hint!


#5

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