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

Maria Blanton
Maria Blanton
5,672 Points

My Story Maker

var animal = prompt("Choose an animal");
var adjective1 = prompt("Choose an adjective");
var weather = prompt("Pick a type of storm");
var body = prompt("Name a body part");

alert("Good job! You're done! Click Ok to read your story.");    

var story = "There once was a " + animal + " that was so " + adjective1 +
  " that all of the townspeople would laugh at him. " + "But one day there was " +
  weather + " and the townspeople were all trapped. " + "Even though they were mean to the " +
  animal + ", he had a " + body + " of gold and couldn't let them suffer. " + " The " +
  animal + " and his " + body  + " of gold saved the townspeople. " +
  "But since all of the townspeople were jerks they still laughed at the " + animal +
  " for being " + adjective1 + " so he moved to a new city and lived happily ever after.";

document.write(story);

alert("I hope you enjoyed that. If you want to create another story, just refresh the page!");

Hi Maria,

I made a few tweaks to the formatting and added markdown to help make the code more readable. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.

Cheers!

1 Answer

That's really cool :)

My choices were:

  • animal = pig
  • adjective = fat
  • weather = snow
  • body = leg

The story worked out quite nicely.

Cheers