How can I add a variable to console.log?
You can use another console method:
let name = prompt("what is your name?");
console.log(`story ${name} story`);
console.log
takes multiple arguments, so just use:
console.log("story", name, "story");
If name is an object
or an array
then using multiple arguments is better than concatenation. If you concatenate an object
or array
into a string you simply log the type rather than the content of the variable.
But if name is just a primitive type then multiple arguments works the same as concatenation.
Then use +
to combine strings:
console.log("story " + name + " story");