简体   繁体   中英

how to use var properly

I just started learning Javascript on codecademy and don't know what is the problem with this code.

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!")
};

It says there's something wrong with variable. It might be a too easy question, but I don't know how to figure it out.

In javascript it's not allowed to have a hard break in a string.

this line:

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

should be:

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

Your code works fine for me. The only thing is a newline in the second console.log statement , but I don't know if this was just a copy&paste error you made while posting.

The issue like Klaasman pointed out, is that you had a newline break.

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

If you want strings to go more than one line you have to use \\ to tell JavaScript that "The string is continued on the next line"

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

This way you could write the same string like this:

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

You also forgot a semicolon on your last console.log statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM