If else statement not working as expectef


#1

Hi
I am trying to solve the story heat up of "if else".
This is the code I am using

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 {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}

But I am getting an error
"Oops, try again. Did you add an if statement to your code?"

When I checked the chrome console, its showing

Uncaught [object Event] composer_controller-a0f22f1e389332abcefe4ae0076169ef.js:1 Uncaught [object Event]

I am using chrome version
Version 48.0.2564.109 m

Please help


#2

You use " " for strings, not '
Try userAnswer === "Yes"


#3

in Javascript both single and double quotes can be used for strings.
@scriptjumper12798 That error you are getting is probably of the error the shell you are running your code in is throwing.
Your code is right but perhaps you should check your strings make sure it is exactly what was given


#4

it shows the same error


#5

Maybe you forgot to add or include your previous code.

Try to add this on the top

var age = prompt("Whats your age?");

if (age < 13){
    console.log("You are allowed to play BUT I dont take the responsibility");
    }

else{
    console.log("You can do it!");
    }

#6

thank you :slightly_smiling:


#7

thanks so much man really nice!


#8

welcome! thank you is enough, i'll just ignore the "man". hahaha, happy coding!