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

Carleen Hall
seal-mask
.a{fill-rule:evenodd;}techdegree
Carleen Hall
Front End Web Development Techdegree Student 3,158 Points

Concatenation

After combining strings for a visitor's info. The word "visitor" is coming back instead of the person's name. The pop up box shows up but I after typing my name in the box. "Hello visitor Welcome to my site" shows up instead of my name.

var visitor = prompt("what is your name?"); var message = "Hello " + "visitor" + "Welcome to my site"; document.write(message);

1 Answer

Lucas Santos
Lucas Santos
19,315 Points

That's because you have quotation marks around the word "visitor". When you have quotation marks around a word it means that word is a String and will show up as the word you typed. In other words you should not have quotation marks around the word visitor because that is a variable

What your code should look like:

var visitor = prompt("what is your name?"); 
var message = "Hello " + visitor + "Welcome to my site";
document.write(message);