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) Working With Numbers The Mad Libs Challenge Revisited

Templated JS not running completely when I 'Preview'.

All I'm trying to do is run the program that's already been input in the JS file in Workspaces:

var adjective = prompt('Please type an adjective');
var verb = prompt('Please type a verb');
var noun = prompt('Please type a noun' + questionsLeft);
alert('All done. Ready for the message?');
var sentence = "<h2>There once was a " + adjective;
sentence += ' programmer who wanted to use JavaScript to ' + verb;
sentence += ' the ' + noun + '.</h2>';
document.write(sentence);

However, when I run the program I just get the 'adjective' prompt, then the 'verb' prompt and the program stops. I haven't made any edits to this code so just wondering why the starting code is not running completely?

Also, when I run this in Console in Chrome, the program executes correctly!

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

I formatted your code for proper viewing in the Community Forum. Please see the Markdown Cheatsheet on how to do this.

There is a type error in the code you provided. In the noun variable, there seems to be + questionsLeft in the code line. This variable isn't defined anywhere, and doesn't seem to belong there. Once that is deleted, the code executes just fine.

var noun = prompt('Please type a noun');  //deleted errant code

:dizzy:

Thanks for the help Jason, and apologies to the Community for the formatting mistake.

Even after removing that '+ questionsLeft' bit, I am seeing the exact same issue. The odd thing is that if I just paste this code into Console in Chrome, it executes perfectly. Do you know what could be causing the issues in browser?

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Not 100% sure. I ran the code in the consoles for Firefox and Chrome and did get the same results (complete execution).

The only thing I can think of is a browser setting that is preventing multiple pop-ups (alerts). I know that I get a manual warning and option to 'kill' pop-up alerts after the second one. Maybe you have a setting that automatically 'kills' after the second one.

:dizzy: