1

我刚开始在 codecademy 上学习 Javascript,不知道这段代码有什么问题。

var feedback = prompt("Rate this game out of 10");
if(feedback > 8) {
    console.log("This is just the beginning of my game empire. Stay tuned for more!");
}
else {
    console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!")
};

它说变量有问题。这可能是一个太简单的问题,但我不知道如何弄清楚。

4

3 回答 3

3

在 javascript 中,不允许在字符串中出现硬中断。

这一行:

console.log("I slaved away at this game and you gave me that score?! The nerve! Just you          
wait!")};

应该:

console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!")};
于 2013-05-14T07:26:51.120 回答
2

你的代码对我来说很好。唯一的事情是第二个 console.log 语句中的换行符,但我不知道这是否只是您在发布时犯的复制和粘贴错误。

于 2013-05-14T07:28:09.890 回答
0

像 Klaasman 指出的问题是你有换行符。

console.log("This is a very long string
that went more than one line long");

如果你想让字符串超过一行,你必须使用 \ 告诉 JavaScript “字符串在下一行继续”

console.log("This is a very long string \
that went more than one line long");

这样你就可以像这样编写相同的字符串:

console.log("This \
is \
a \
very \
long \ 
string");

您还在最后一个 console.log 语句中忘记了分号。

于 2013-05-14T23:49:27.647 回答