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 trialManda Schalin
1,346 Points'Unexpected end of input' console error msg. I've closed the 'else' statement with a curly brace; unsure of the problem
if ( correctGuess ) {
document.write('<p>You guessed the number!</p>');
} else {
document.write('<p>Sorry. The number was ' + randomNumber + '. </p>');
}
Moderator edited: Markdown added so that code renders properly in the forums.
3 Answers
I Dilate
3,983 PointsHi Manda,
Is there anything else in your script?
The code you pasted looks syntactically fine, so perhaps the problem lies elsewhere?
Thanks, Rich
Nicholas Zavras
6,277 PointsSo I've just got mine to work and it turned out to be a curly braces thing, I've spaced out the code you pasted here and I noticed you have one too many closing curly braces on one part, and you're missing a closing curly brace on another. I've typed in ERROR where I think the problem is
if (parseInt(guess) === randomNumber ) { correctGuess = true; }
if ( correctGuess ) { document.write('<p>You guessed the number!</p>'); }
else if ( parseInt(guess) > randomNumber ){ var lesserGuess = prompt('The number is less than this, guess again!') ERROR NO CLOSING BRACE
if (parseInt(lesserGuess) === randomNumber){ correctGuess = true; }
}<--ERROR CLOSING BRACE else if ( parseInt(guess) < randomNumber ){ var greaterGuess = prompt('The number is greater than this, guess again!') ERROR NO CLOSING BRACE
if (parseInt(greaterGuess) === randomNumber) { correctGuess = true; }
if ( correctGuess ) { document.write('<p>You guessed the number!</p>'); } else { document.write('<p>Sorry. The number was ' + randomNumber + '. </p>'); }
Manda Schalin
1,346 PointsThanks very much Nicholas, I'll have to check more carefully from now on. Cheers!
Manda Schalin
1,346 PointsManda Schalin
1,346 PointsHi Rich, Thanks a lot for checking! The console pinpoints the error to line 23 (Uncaught syntax error: unexpected end of input). I've been looking over the previous script, but can't seem to identify the problem.
I'll paste the rest of the script below.
Cheers, Manda
var correctGuess = false; var randomNumber = Math.floor(Math.random() * 6 ) + 1; var guess = prompt('I am thinking of a number between 1 and 6. What is it?'); if (parseInt(guess) === randomNumber ) { correctGuess = true; } if ( correctGuess ) { document.write('<p>You guessed the number!</p>'); } else if ( parseInt(guess) > randomNumber ){ var lesserGuess = prompt('The number is less than this, guess again!') if (parseInt(lesserGuess) === randomNumber){ correctGuess = true; } } else if ( parseInt(guess) < randomNumber ){ var greaterGuess = prompt('The number is greater than this, guess again!') if (parseInt(greaterGuess) === randomNumber) { correctGuess = true; } if ( correctGuess ) { document.write('<p>You guessed the number!</p>');
} else { document.write('<p>Sorry. The number was ' + randomNumber + '. </p>'); }