我正在编写关于if / else语句的Codecademy课程,并且我反复收到错误说,"语法错误:意外的令牌"。请帮忙。这是代码:
// Check if the user is ready to play!
confirm("I am ready to play!");
var age=prompt("What is your age?");
if(age<13)
{
console.log("You are allowed to play, but I take no responsibility");
}else{
confirm("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=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.'");
};
答案 0 :(得分:0)
if(userAnswer==="yes");
只需删除&#34;;&#34;
if(userAnswer==="yes")
这就是为什么 - JavaScript(以及大多数语言)会解释如下:
if (condition);
statement;
作为无操作并优化它,因为上面的伪代码实际意味着:
if (condition) <nothing!>;
statement;