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 Solution

How can I get my program to stop looping? Once you reach the end and the story appears, I start to get prompts again.

var adjective = prompt("Give me an adjective:"); alert("You said: "+adjective+","+" right?")

var bodyPart = prompt("Give me a body part:"); alert("You said: "+bodyPart+","+" right?");

var verb = prompt("Give me a verb:"); alert("You said: "+verb+","+" right?");

var remedy = prompt("Give me a remedy for illness:"); alert("You said: "+remedy+","+" right?");

var tvShow = prompt("Give me a tv show:"); alert("You said: "+tvShow+","+" right?");

var furniture = prompt("Give me a piece of furniture:"); alert("You said: "+furniture+","+" right?");

var beverage = prompt("Give me a beverage:"); alert("You said: "+beverage+","+" right?");

alert("Are you ready to read your story?");

document.write("<h2>I am feeling " + adjective + " today." + " My " + bodyPart + " aches and I can't " + verb + "." + " I will take some " + remedy + "," + " watch " + tvShow + "," + " rest on the " + furniture + "," + " and drink some " + beverage + "." +" I hope I get better soon!</h2>")

console.log('End Program');

Gareth Gomersall
Gareth Gomersall
2,890 Points

It doesn't loop for me either, was tested in Chrome btw.

3 Answers

I had the same problem, It happened for me after I added the <script></script> tags to the html sheet before noticing that the sheet already had script tags in the body. I'm positive I didn't add the tags there, because it was my first time doing the challenge and I added them to the head tag and then the program executed two times in a row. solved it by removing the set of script tags I had placed and left the tags that were in the body.

I think you forgot to put semi-colon to end your document.write

rydavim
rydavim
18,814 Points

I'm not seeing the same behavior you are. Your prompts and alerts all run for me once, and then print the result to the webpage. It does not loop or repeat after that. This was tested using IE 10 previewed from workspace.

Can you tell me what browser or program you're using to preview your code? Could something be refreshing your page and starting it over from the beginning?