If/else statement wrong?


#1


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


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


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 Justin 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

That should be ===. This way, you assign both value and data-type.

See full of the if/else below:

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

#3

Hey,
First of all thanks for this quick reply.
I tried using your code but I get the exact same error message. In my prompt windown I type "yes", is that correct? What else should I try?

Thank you
Leo


#4

Please post your new full-code.

Thank you! :slight_smile:


#5

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


#6

Please is this really all your code?

I thought it should include a set of code to first prompt for users age?


#7

I just checked another post and I may have deleted the first part.
Now it's like this and working:
confirm("I am Ready to play!");

var age = prompt("What's your age?");
console.log (13)

if (age < 13)
{
console.log("Get outta here!");
}
else
{
console.log("Time to rock!");
}
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 Justin 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.'");
}


#8

Thank you very much for helping me!
I thoght it would be stuck in the box and deleted the first part.


#9

Oops! You're welcome.

That's why I needed you to post full-code so you could see the issue yourself.

Have fun coding! :slight_smile:


#10

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