Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
What is wrong with my Java code?
I'm doing this thing that is teaching me how to use JavaScript. It says that they're is a error on line 19 saying "Expected an identifier and instead saw 'else'. missing ';' before statement"
Here is my script:
// Check if the user is ready to play!
confirm("Ready");
var age = 13;
age = prompt("What's your age");
if(age > 13)
{
console.log("You're allowed to play, but I take no responsibility.");
}
else
{
console.log("Play on!");
}
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;
userAnswer = prompt("Do you want to race Bieber on stage?");
if(userAnswer === "yes","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 Answers
- ChrisLv 77 years ago
You have made the common mistake of placing a semi-colon directly after the if condition:
if (userAnswer === "yes","Yes"); <--
This will stop the entire if check in its tracks, and treat everything after the semi-colon as separate code.
Also, you can't do a test like this.
If you want to catch "yes" and "Yes", you have two options:
if (userAnswer === "yes" || userAnswer === "Yes")
|| is the boolean OR operator.
Alternatively:
if (userAnswer.toLowerCase() === "yes")
This will also catch "YeS" and "yES" and every other possible capitalization.
- DominicLv 77 years ago
if(userAnswer === "yes","Yes"); {
That is incorrect.
if (userAnswer === "yes" || userAnswer === "Yes") { ...
Dunno if that will solve your problem though.