javascript - 语法错误 : Unexpected token } (www. codecademy.com)

标签 javascript

我目前遇到一个问题,每当我尝试将代码提交到 CodeCademy 时,都会收到错误消息。 语法错误:意外的标记}

这是代码:

 // 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 - 语法错误 : Unexpected token } (www. codecademy.com),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31661089/

相关文章:

javascript - 如何使隐藏的元素更快地弹出(jquery/css)

javascript - 如何在 Angular 的相对路径中查找资源

javascript - 我如何更改此功能,以便每次点击一次只能播放一首随机歌曲? (JavaScript)

javascript - 如何在内容/风格有所变化的情况下为外部网站提供服务?

javascript - 如何检测 iframe javascript 中单击了哪个元素

javascript - 用于从弹出式日历中选择日期的定期维护的 Javascript 库?

javascript - 总是收到 android.database.sqlite.SQLiteException : near "Time" when running SQLite

javascript - 如何将嵌入/嵌套的 FormGroup 转换为 FormData

javascript - 尽管 tsconfig 包含 `jsx` 选项,但 Jest 拒绝解析 JSX

javascript - CSS 中具有透明度的图像的线性渐变