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 trialDaniel Taylor
4,448 PointsJavaScript: prompt command runs twice
Hello,
I'm very new to JavaScript and would really appreciate some help.
I've been working on the Story Maker Challenge - in JavaScript Basics.
Any variable I create with a prompt seems to run twice and get printed to the document twice - I have no idea why?
var collectAdjective = prompt("Please write an adjective!"); document.write(collectAdjective);
Thanks in advance.
Dan
3 Answers
Emeka Farrier
Courses Plus Student 2,892 PointsThe code works fine when I test it prompts once then writes the answer to the page. Can u show me the rest of the related code?
Daniel Taylor
4,448 PointsHi Emeka,
Thanks for taking a look - that's interesting to know.
Unfortunately I deleted the rest of the code before posting. I decided to go back to the beginning and just get that statement working. But still using just that statement I'm prompted twice in Safari, Chrome & Firefox.
This may be a silly question but could it be a browser setting?
Thanks, Dan
Rachael Axtman
1,528 PointsHey Dan,
I know this was posted a year ago, but I ran into this issue so hopefully this will help someone else. The issue with this specific exercise is if you look in the HTML document (index.html) the following script src is in the head and the body: <script src="story.js"></script>. Because it was calling the same thing out in two places it was asking for the information twice. I removed it from the head and it ran just once.
Emilia Lovatto
1,118 PointsThanks! Just helped me now! :DDD