I'm a python programmer and in Python, the \\n renders a new line like so:
print("Hello \n World")
Hello
World
But I'm trying to do that in Javascript with the following block of code:
if (userInput == wrongAnswer){
let finalScore = initialScore + scoreForA;
console.log(finalScore);
if (finalScore == 5){
console.log(rightScore);
}
else{
console.log("Initial score:", initialScore, "\n", outputA, "\n", "Final score:", finalScore);
}
}
Edit: By the way, I've defined these variables already.
But it gives me:
Is the \\n supposed to auto-indent Wrong answer and Final score after making a new line in JavaScript?
Note that you're providing multiple arguments to console.log
, so the python analog would be print("Hello\\n", "World")
which would add a space on the second line as well. Multiple arguments are always separated by a space, if you don't like that, concatenate them or use a template literal:
console.log(`Initial score: ${initialScore}\n${outputA}\nFinal score:${finalScore}`)
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.