Search code examples
javascriptpromptvar

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.


Solution

  • 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.