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 trialJan Ondrášek
Full Stack JavaScript Techdegree Student 1,326 PointsUnexpected end of script
I am trying to run a similar version of the script, but I am getting an error "Unexpected end of script" - I think that my code is similar to the one in the video but I have to be making error somewhere :/ My script follows below:
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;
} else if ( parseInt(guess) > randomNumber ) {
var guessLess = prompt ("The number I was thinking of is lower.");
if (parseInt(guessLess) === randomNumber) {
correctGuess = true;
}
else if (parseInt(guess) < randomNumber ) {
var guessMore = prompt ("The number I was thinking of is higher.");
if (parseInt(guessMore) === randomNumber) {
correctGuess = true;
}
if ( correctGuess ) {
document.write('<p>You guessed the number!</p>');
} else {
document.write('<p>Sorry. The number was ' + randomNumber + '.</p>');
}
Jan Ondrášek
Full Stack JavaScript Techdegree Student 1,326 PointsThank you, Haitham, I was able to locate the problem after your suggestion :)
Haitham Rizk
631 PointsHaitham Rizk
631 PointsHey Jan, you have a syntax error in your code because there're two curly brackets missing " } " for two of your if conditions, you can add }} . at the end of your code just to get out of this error, but you have to find the correct place in your for those curly brackets to end the if conditions correctly. you are the only one who know where the if condition should end :)