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 The Variable Challenge

Check out my code for this challenge and let me know of any pros and cons. https://w.trhou.se/hu4mdtm6gd

Here's the link to the code https://w.trhou.se/hu4mdtm6gd

Just let me know any pros and cons so I can improve. Thanks in advance1

1 Answer

Robert Stefanic
Robert Stefanic
35,170 Points

Lookin' good. :)

My only suggestion would be that you don't need to create all those variables like var lineOne, var lineTwo, because that wastes allocated memory. Instead, just store it all in one concatenating variable like this:

var completeStory = "Dude," + nameNoun + " last night we got wasted off those " + drinkName;

completeStory += ". Then " + crushName + " walks in and invites us to " + vacationName + ".";

completeStory += "We get there and ran into " + leastcelebrityName;

completeStory += ". Next thing I know your favorite " + favcelebrityName + "  is talking and laughing with us.";

completeStory += "I go to the bathroom and when I came back you " +  nameNoun + " plus " + leastcelebrityName + " and " + favcelebrityName + " was swimming in a pool filled with " + snackName + ",";

completeStory += "Seiously " + nameNoun  + ", you know how to party and one more thing " + leastcelebrityName + " told me to give you their number, they want to see you again.";

That way, you can just define one variable and keep adding onto it.

I didn't even know I could do that... Thanks a lot Robert, I learned something new. ^_^