Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Combining Strings

Marc Cook
Marc Cook
4,610 Points

Combining string help

Why is this code not working? the prompt works and my name shows up but i cannot get the string to show up. Thank!

Marc Cook
Marc Cook
4,610 Points

would help if i posted the code!

var visitor = prompt('What is you name?'); var message = 'Hello ' + visitor + ". Welcome."; message += "I great you stop

2 Answers

Colin Bell
Colin Bell
29,679 Points

Where are you wanting the string to show up?

Right now, you're storing the prompt input into the visitor variable. Then, you're concatenating it in between two strings and setting that to the message variable. Then you're concatenating another string to the end of that variable and saving it as itself. Then your code ends.

If you were to do something like alert(message); you should get a pop up with your string as the message.

var visitor = prompt('What is you name?'); 
var message = 'Hello ' + visitor + ". Welcome."; 
message += "I great you stop";
alert(message);
Marc Cook
Marc Cook
4,610 Points

thank you for the fast reply and help, I see what you are saying with the pop up window and i tried it and was successful. On the other hand i am still confused about how to get it to write the strings on the console as in the video? I tried the exact same code he demonstrated and it still wouldn't work, would that be a browser issue? I currently use chrome

Colin Bell
Colin Bell
29,679 Points

Hmmm. Does this work for you?

var visitor = prompt('What is you name?'); 
var message = 'Hello ' + visitor + ". Welcome."; 
message += "I great you stop";
console.log(message);