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

Ray Dunbar
Ray Dunbar
7,367 Points

Not getting second line to show correctly when previewing.

I am typing what is shown on screen but when I refresh the preview it will only show the name typed into the prompt and not "Hello". What am I missing?

var visitorName = prompt('What is your name?'); var message = "Hello " + visitorName; document.write(visitorName);

1 Answer

Steven Parker
Steven Parker
186,477 Points

The last line is writing the contents of "visitorName", but the combined string is in "message".

Ray Dunbar
Ray Dunbar
7,367 Points

Thank you! I honestly don't know how I missed that. I must have looked at it a thousand times.