我目前遇到一个问题,每当我尝试将代码提交给CodeCademy时,都会出现错误。 SyntaxError: Unexpected token }
这是代码:
// Check if the user is ready to play!
confirm("Are you ready to play")
var age = prompt("What is your age?")
if (age === 13) {
console.log("You are old enough to play");
} else {
console.log("Play On!")
}
var JustinBieberSux = "You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'"
console.log(JustinBieberSux);
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = "Do you want to race Bieber on stage?"
prompt(userAnswer);
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.'")
}
var feedback = prompt("Rate the Game out of 10?")
if (feedback < 8) {
console.log("Thank you! We should race again at the next concert!")
} else {
console.log("I'll keep practicing coding and racing."
}
任何帮助将不胜感激。
谢谢,
Sir_smiggles
最佳答案
您最后一个console.log()
通话缺少最后一个括号。
您的代码应如下所示。
// Check if the user is ready to play!
confirm("Are you ready to play");
var age = prompt("What is your age?");
if (age === 13) {
console.log("You are old enough to play");
} else {
console.log("Play On!");
}
var JustinBieberSux = "You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'";
console.log(JustinBieberSux);
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = "Do you want to race Bieber on stage?";
prompt(userAnswer);
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.'"); }
var feedback = prompt("Rate the Game out of 10?");
if (feedback < 8) {
console.log("Thank you! We should race again at the next concert!");
} else {
console.log("I'll keep practicing coding and racing.");
}
我还在适当的地方添加了分号。习惯在每一行的末尾使用它们,否则在兼容性较差的浏览器中会遇到语法错误。
关于javascript - SyntaxError:意外 token }(www.codecademy.com),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31661089/