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

Atanas Sqnkov
Atanas Sqnkov
14,981 Points

Repeating prompts.

Hello guys!

I am having a small problem here. This is my code :

var noun = prompt("Enter a noun:");
var verb = prompt("Enter a verb:");
var adjective = prompt("Enter an adjective:");

var sentence = "Hello, I am a " + noun + " and I like to " + verb + " in my spare time. This makes me feel " + adjective;

document.write(sentence);

Everything works well, but after I enter all three prompts, I get prompted all over again.

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi,

Is this all of your code? I just tested this code and only got the three prompts then the message written to the page.

I don't see how it could repeat unless you re-load the page.

Atanas Sqnkov
Atanas Sqnkov
14,981 Points

I am using the Workspace provided. I am previewing it in my browser and this is what happens. Yes, this is all of my code.

6 Answers

Howdy,

I tried your code in Workspaces and the prompts did not repeat and seemed to work perfect. I was able to get your code to write to my browser as well.

I tested using Chrome 38 on a Mac iwith OS X 10.9.5.

Perhaps Workspaces was having an issue or maybe you should try the code in another browser.

What does your HTML file look like? Have you added the script.js file to it twice? It was already added so I didn't need to add it.

Atanas Sqnkov
Atanas Sqnkov
14,981 Points
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>The Story Maker</title>
 </head>
<body>
  <div class="container">
  <h1>The Story Maker</h1>
  <script src="story.js"></script>
  </div>
</body>
</html>
Atanas Sqnkov
Atanas Sqnkov
14,981 Points

My guess would be the same, this is some kind of a bug in the Workspace. But as it seems it only happens to me so this might not be considered a problem.

Thank You both! Cheers!

I'm having the same problem in Mozilla and Chrome browsers. Please help with this as it is very frustrating to not know the cause of this before proceeding with this track.

John Enderby
John Enderby
11,730 Points

I know this is a small thing, but in the challenge video Dave suggests adding a script tag as part of the challenge. I did this and got 6 prompts.

What I didn't realise was that there was already a script tag in the workspace nested in the div. Check over it again. I was wondering the same until I read the index.html file over again. It might be a slightly different workspace that is generated for this video.

Hope that helps!

Okay so after allowing several weeks to pass before coming back to the issue of multiple prompts popping up I've determined why this is happening. The code below is my incorrect JavaScript:

var message = 'A farmer '; var verb = prompt('Type a verb!'); message += verb + ' off a '; var adjective = prompt('Type an adjective!'); message += adjective + ' '; var noun = prompt('Type an noun!'); message += noun + '!' prompt('Type a verb!'); prompt('Type an adjective!'); prompt('Type an noun!'); document.write(message);

What I determined is that once you declare a variable which is designed to store user input via the prompt method this is sufficient and JavaScript knows to display a prompt box without another separate prompt method being typed out after the variable which will store the input from the prompt is declared. Correct code should be as I've typed below. Notice I've removed 3 prompt statements as they are not needed for JavaScript to execute the prompts associated with the variables verb, noun, and adjective.

var message = 'A farmer '; var verb = prompt('Type a verb!'); message += verb + ' off a '; var adjetive = prompt('Type an adjetive!'); message += adjetive + ' '; var noun = prompt('Type an noun!'); message += noun + '!' document.write(message);

***Hope this helps.