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 trialKevin Dunn
6,623 PointsMy code works in the console, but not when previewing it in the browser
So the code below works correctly in the console, but not when previewing it from the workspace. Any ideas what could be wrong?
var questions = 3;
var questionsLeft = ' [' + questions + ' questions left]';
var adjective = prompt('Please type an adjective' + questionsLeft);
questions -= 1;
questionsLeft = ' [' + questions + ' questions left]';
var verb = prompt('Please type a verb' + questionsLeft);
questions -= 1;
questionsLeft = '[' + questions + ' questions left]';
var noun = prompt('Please type a noun' + questionsLeft);
questions -= 1;
questionsLeft = '[' + questions + ' questions left]';
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);
Moderator Edited: Added Markdown (please refer to the Markdown Cheatsheet) so the code is readable in the forum
3 Answers
chris jarvis
8,624 PointsThat code works. Did you figure it out?
Kevin Dunn
6,623 PointsHmm, very strange. It didn't seem to work earlier but now it does. Not too sure what was wrong but thanks for your time guys!
chris jarvis
8,624 PointsMight have just forgot to save, or could have been a connection problem.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsThe posted code seems to work fine.
You probably need to make a snapshot of your workspace and post the link to it here.