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

Jordan Stoddard
PLUS
Jordan Stoddard
Courses Plus Student 508 Points

So here's how I completed the variable challenge, but I feel like it's probably super clunky and could be done easier.

alert("Want to play a game? Just fill in the blanks"); var verb = prompt("Ok just enter a verb:"); var adjective = prompt("Ok now enter an adjective:"); var noun = prompt("Ok now enter a noun:"); alert("Great job, here's your story:"); document.write("I ") + document.write(verb); + document.write(" into a ") + document.write(adjective) + document.write(" dumpster that had a ") + document.write(noun) + document.write(" in it. That ") + document.write(noun) + document.write(" ate my face.");

Could any more experienced developers give me some tips? :)

2 Answers

alert("Want to play a game? Just fill in the blanks");
var verb = prompt("Ok just enter a verb:");
var adjective = prompt("Ok now enter an adjective:");
var noun = prompt("Ok now enter a noun:");
alert("Great job, here's your story:");
var story = "I " + verb + " into a " + adjective + " dumpster that had a " + noun + " in it. That " + noun + " ate my face."
document.write(story);
Junet Ismail
Junet Ismail
3,563 Points

for what the task requires you to do your syntax seems to be spot on. Depends what you want it to do would dictate whether the final code could be made more efficient or not. Mine is quite clunky at the moment but I could streamline it more if i spent additional time on it

Junet Ismail
Junet Ismail
3,563 Points

This is my version for people to play around with . though i could refine it down i went a little OTT with the design as i was enjoying myself a bit too much .. others might find it useful. I've commented all the js file to help. Ping me with any questions:-

https://teamtreehouse.com/workspaces/40762235#