JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge

Jordan Stoddard
PRO
Jordan Stoddard
Pro 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#