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 trialByron Murray
3,915 PointsMy code, a little less
var questions = 3;
var adjective = prompt('Please type an adjective' + ' [' + questions + ' questions left.]');
var verb = prompt('Please type a verb' + ' [' + (questions -= 1) + ' questions left.]');
var noun = prompt('Please type a noun' + ' [' + (questions -= 1) + ' 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);
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsThat won't work because you can't assign/update a variable from within the value you're assigning to another variable. Or in this case, you can't use questions -= 1
to change the value of questions while you're assigning a value to adjective
, verb
or noun
.
You could just print the value of questions
, then questions - 1
and then questions - 2
, but then if you're doing that, you might as well just write the number in.
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsNicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsAre you having a problem with this code?