I'm making a simple game in JavaScript but in the story I need it to say the players name. so what I have so far is:
var name = prompt("what is your name?"); console.log("story" name "story);
how do I do the second line? or there is another way I could do this. Is it possible to have 2 console.log();
on 1 line in the console?
log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console. log(A);
When we want to print a message containing multiple variables along with a message, we can format console. log() accordingly by: Using specifiers like %s, %i, %f etc.
To create a multi line strings when printing to the JavaScript console, you need to add the new line character represented by the \n symbol. Alternatively, you can also add a new line break using Enter when you use the template literals syntax.
console. log() is used as a debugging tool to help you understand what your code is doing. By displaying a message containing either descriptive text that tells you what is happening or the value of particular variables, you can follow along as your code executes. The user of your app will not see the console.
Then use +
to combine strings:
console.log("story " + name + " story");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With