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 trialBen Mohammad
5,659 PointsThe prompt dont print how many questions left...
I dont even see the first prompt saying how many questions left. if someone could point me in the right direction it would be appreciated.
var questions = 3;
var questionsLeft = '[' + questions +' questionsLeft]';
var adjective = prompt('Please type an adjective' + questionsLeft);
questions -= 1;
questionsLeft = '['+questions +'questionsLeft];
var verb = prompt('Please type a verb' + questionsLeft);
questions -= 1
var noun = prompt('Please type a noun' + questionsLeft);
questions -= 1
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);
3 Answers
miikis
44,957 PointsHey Ben,
You got a typo on Line 5 — you're missing a closing single-quote. Fix that and your code will run as you expect.
Ben Mohammad
5,659 Pointsyeah like mine it runs but it dont prompt the questions left......... im lost mate!!
miikis
44,957 PointsI'm not sure what you mean, man; the questionsLeft is being decremented and displayed in the prompt view — is that not happening for you?
Here let's clean up your code a little bit so it reads better:
var remainingQuestions = 3; // Just a counter that we're going to subtract from...
var adjective = prompt("Please type an adjective. There are only " + remainingQuestions + " questions left!");
remainingQuestions -= 1; // Subtract 1 from that counter ...
var verb = prompt("Please type a verb. There are only " + remainingQuestions + " questions left!");
remainingQuestions -= 1; // Subtract 1 from that counter ...
var noun = prompt("Please type an noun. There are only " + remainingQuestions + " questions left!");
remainingQuestions -= 1; // Subtract 1 from that counter ...
// I use confirm() instead of alert() because it's options are "yes" and "no" — unlike alert's which is just a "cancel" button
// Really though, it doesn't matter. Your way works just as fine.
confirm("That's it, no more questions! Ready for this shit?");
document.write(
"<h2>" +
"There once was a " + adjective +
" programmer who wanted to use JavaScript to " + verb +
" the " + noun + "!" +
"</h2>"
);
Let me know if you have any questions.
Ben Mohammad
5,659 Pointsi sussed it thanks for elaborating on it though, i needed that!
Ben Mohammad
5,659 PointsBen Mohammad
5,659 PointsquestionsLeft = '[' + questions +' questionsLeft]';
still don't execute.........
you were right sussed it! thanks mikis
miikis
44,957 Pointsmiikis
44,957 PointsUnless you changed something else, it should run; that was the only thing that kept it from running in my console. The below code should run without error: