Race Bieber on Stage doesn't work!


#1

Thats my code, it says " Did you remember to put in the 'no' answer option?"
I also tried it with
if...
else if...
else...
Someone pls help :slightly_smiling:

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{
if(userAnswer==="no") {
console.log("CHICKEN!");
}else{
console.log("You did something wrong");
}
}


#2

@passoe2,
In this situation
you will have to use an IF ELSE-IF ELSE statement structure..

if ( condition ) {
   //IF code-block
}
else if ( condition ) {
   //ELSE-IF code-block
}
else {
   //ELSE codeblock 
}

It could also be
that the code-checker is checking on existence of a 'no' instead of your "no"
but more important
is that you use the EXACT text's as mentioned in the Instructions.


#3

hello. can you give any example for this structure?


#4

Okay lol, the problem was the quote in console.log for the "no" answer:
this does work:


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 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("You did something wrong");
}


#5

Whats the different between 'yes' and the "yes"? Both works fine too me.:smiley:


#6

@teikfai,
Both the singel-quoted-string 'yes'
and the double-quoted-string "yes"
are valid string notations.

Javascript internally works with single-quoted-strings

Thus if you have a string like

"This string has an 'internal' string"

Javascript wil have an internal representation of

'This string has an \'internal\' string'

----------------------------------------------------------

During the Course's the code-checker mechanisms can check

  • the exact code definition/usage as mentioned in the Instructions
  • or the EXACT output's as specified in the Instructions

#7

Actually "no" was fine, you just had console.log("CHICKEN!") as the answer from no instead of

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