我刚刚开始在代码学院学习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!")
};
它说变量有问题。这可能是一个太简单的问题,但是我不知道如何解决。
最佳答案
像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语句中的分号。
关于javascript - 如何正确使用var,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16537328/