How can I add a variable to console.log?

Bradley McInerney picture Bradley McInerney · May 17, 2013 · Viewed 225.3k times · Source

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?

Answer

Joseph picture Joseph · May 17, 2013

Then use + to combine strings:

console.log("story " + name + " story");