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 trialJay Valentine
Courses Plus Student 4,389 PointsMy finished story.. (Can i improve it?)
alert("Click the button if you are ready to create a story with me.");
var adjOne = prompt("Write a word that describes something for example..'Big' 'boring' 'purple' are all describing words");
var adjTwo = prompt("Write another describing word");
var mainPerson = prompt("Give the Main character a Name (she is a girl)")
var hobbyOne = prompt("Write a Hobby for the main characgter");
var placeOne = prompt("Name a place");
alert("Good job! You're done! Click Ok to read your story.");
var story = "There was once a very " + adjOne + " and " + adjTwo + " girl, her name is " + mainPerson + ". " + mainPerson + " has lots of favourite things to do, like cliff diving at the North Pole and " + hobbyOne + ". " + " Every year " + mainPerson + " loves to go to " + placeOne + " for a holiday with her family.";
document.write(story);
1 Answer
Blake Lieberman
23,772 PointsFor the sake of organizing your code. A habit you want to begin now. Start by grouping your global variables at the top. You don't have to repeat the var if you list them out as I have done below separating the variables with commas. Next we group the alerts as they begin the user interaction to follow your story. Last we place your document.write(story) at the bottom.
Organizing code is important for scalability and for collaboration with others or your future self.
var adjOne = prompt("Write a word that describes something for example..'Big' 'boring' 'purple' are all describing words"),
adjTwo = prompt("Write another describing word"),
mainPerson = prompt("Give the Main character a Name (she is a girl)"),
hobbyOne = prompt("Write a Hobby for the main character"),
placeOne = prompt("Name a place"),
story = "There was once a very " + adjOne + " and " + adjTwo + " girl, her name is " + mainPerson + ". " + mainPerson + " has lots of favourite things to do, like cliff diving at the North Pole and " + hobbyOne + ". " + " Every year " + mainPerson + " loves to go to " + placeOne + " for a holiday with her family.";
alert("Click the button if you are ready to create a story with me.");
alert("Good job! You're done! Click Ok to read your story.");
document.write(story);