Javascript 5. The story heats up! does not have the correct instructions


#1

The instructions for javascript "5. The story heats up" asks for an if /else: "Use an if / else statement to write out the last part of this game!"

However, if / else breaks. I have copy and pasted past working solutions and it fails. Only using two ifs works:

if(userAnswer ==="yes"){
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");

}
if(userAnswer ==="no"){
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");


#2

@nyemichaelw instead of this:

you should just have:

else{
       // code code
}

if you replace that your code should work


#3

The same thing happened to me. Apparently the only way to get through this lesson is writing two different "if". Using "else" does not work at all.


#4

You should already have your first if statement from when you asked the user for their age. If you've lost that part of your code then that causes a problem.


#6

No,, you misunderstand: Your Reply to Bieber is a "Yes" or a "No", so they are correct:

The "Else" statement handles cases when the Answer does not match what the first check or if someone hits cancel or otherwise does not provide an answer that matches what the if() clause is checking.

To check for "No", you would need another If statement after checking for "Yes"

if(answer=='yes')
{
    Action A
}
if(answer=='No')
{
    Action B
}
else
{
    Action C
}

Technically, as long as the answer isn't "Yes" you'd want the same "Else" output, but they're correct in that branching paths require more than just a simple If/Else statement


#7

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