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 trialMarc Cook
4,610 PointsCombining 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!
2 Answers
Colin Bell
29,679 PointsWhere 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
4,610 Pointsthank 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
29,679 PointsHmmm. 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);
Marc Cook
4,610 PointsMarc Cook
4,610 Pointswould help if i posted the code!
var visitor = prompt('What is you name?'); var message = 'Hello ' + visitor + ". Welcome."; message += "I great you stop