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 trialTobi Ogunnaike
2,242 PointsCan anyone suggest a more elegant way of adding the periods to my code? Thanks
Here's my code
var statement1 = "What a coincidence, I can't believe your name is " + prompt("Hey, what is your name?" );
var statement2 = " I recently visited " +prompt("Where were you born?" );
var statement3 = " Let's go to " +prompt("What's your ultimate holiday destination?")+ " together";
document.write (statement1 + ".");
document.write (statement2 + ".");
document.write (statement3 + ".");
There should be a way to fit the periods into the first 3 lines of code but I can't figure out how. Thanks!
3 Answers
Rebecca Bompiani
16,996 PointsHi Tobi-
I think you could concatenate them the same way you started:
var statement1 = "What a coincidence, I can't believe your name is " + prompt("Hey, what is your name?" )+".";
Chris Grazioli
31,225 PointsYou could just make one long formatted string that contains your whole var story;
- like the "children's mad lib" they referred to in the video. The "mad lib" would contain blank spaces or your variables, response1, response2, etc.
Put this long formatted string after all the prompts and display it to the page with the document.write(story);
Tobi Ogunnaike
2,242 PointsThanks Rebecca!
Tried that before but it didn't work. Must've been a syntax issue