Trying to add an else to the story


#1


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

else
{
    console.log("Answer yes or no");
}


Just thought that if the user won't pick yes or no, I might just add an "else" to deal with it, the problem is that if the user answers yes/no, it prints w/e yes/no needs to print PLUS the else statements "Answer yes or no", any suggestions how to fix this?

Thanks :slight_smile:


#2

if else syntax:

if(condition){

  //do something
}
else if(condition){

   //do something else

}
else{

  // something else
}

so here

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

and here

if (userAnswer==="no")  // write **else if** instead of **if**

#3

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