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 trialJames Barshaw
9,284 Pointscode won't work for strings and numbers
I am learning about strings and numbers. whats wrong with my code please explain because It won't do anything and I can't figure out whats wrong with it
var questions = 3; var questionsLeft = '['+ questions + ' questions left]'; var adjective = prompt('please type an adjective' + questionsLeft); var verb = prompt ('please type a verb'); var noun = prompt ('please type a noun'); 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
Matthew Long
28,407 PointsLooks like you have some spaces where there shouldn't be. Specifically where you use the addition assignment operator, +=
. You have it as + =
.
There are some other areas where your code could be cleaned up as well. Such as removing the spaces between between alert/prompt and the opening parentheses. This isn't breaking your code though. You could also add a space in your strings so that the words don't run together. But other than the assignment operator it looks ok. You should be able to continue the videos with this:
var questions = 3;
var questionsLeft = '['+ questions + ' questions left]';
var adjective = prompt('please type an adjective' + questionsLeft);
var verb = prompt('please type a verb');
var noun = prompt('please type a noun');
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);
Side note: you can wrap your code snippets in 3 back ticks to have it formatted here in the forums.