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

Ramiro Blanco
Ramiro Blanco
7,266 Points

Here's my version if anyone is stuck

var carryOn = "y"; var story = "";

while (carryOn == "y") { story += prompt("Add a word to your story") + " "; carryOn = prompt("If you want to add another word to your story, enter \"y\"."); }

document.write("Your story is: " + story.trim() + ".");

4 Answers

Hey Ramiro,

I see what you did there, but you can be quite a bit more efficient in your code. A user wouldn't like to have to keep pressing y every time they want to add another word to their story. It would make for a very long and annoying experience. I changed your code around quite a bit so that when you run this, you can just press enter or cancel to break out of the prompt and display the story.

var story = "";

while (true) { 
var partStory = prompt("Add a word/some words to your story or just press enter to cancel.");
//if they press enter or they press cancel, break out of while loop
if (partStory === "" || partStory === null) { break; } 
//Otherwise, add to the story
story += partStory + " "; 
}

document.write("Your story is: " + story.trim() + ".");

This really isn't helpful to beginners.

Are you talking about my code? lol.

The overall scope.

pablocubillos
pablocubillos
10,047 Points

Better a beginners 3-word story:

var firstNoun = prompt ("say a noun"); var firstVerb = prompt ("say a verb"); var firstAdjective = prompt ("say an adjective"); alert ("Are you done?"); var completeSentence = firstNoun +" "+ firstVerb +" "+ firstAdjective; document.write ("You said: " + completeSentence); console.log (completeSentence);