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 trialaliceinwonderland
7,679 Pointsthe console tells me there is a syntax error on line 8. i don't see it. please help. i will attach all my code.
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 guessHigher = prompt("Hint: The number is higher! Guess again.");
}
if (parseInt(guessHigher) === randomNumber {
correctGuess = true;
} else if (parseInt(guess) > randomNumber) {
var guessLower = prompt("Hint: The number is lower! Guess again.");
}
if (parseInt(guessLower) === randomNumber {
correctGuess = true;
}
if (correctGuess) {
alert("AWESOME! Your guess is right!");
} else {
alert("<p>The number is " + randomNumber + ". Click refresh to try again!</p>");
}
1 Answer
Steven Parker
231,275 PointsIt's hard to see without formatting, but it seems that one of the "if" statements is missing a closing parenthesis on the conditional expression. Also, there's an assignment (single "=") in one of the other "if" statements where you probably meant to have a comparison ("==" or "==="). And there's just the opposite (a comparison instead of an assignment) right after that "if". And it may also be that the braces are mismatched (a different number of '{'s and '}'s).
When posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
aliceinwonderland
7,679 Pointsaliceinwonderland
7,679 Pointsi see the closing parenthesis i need. i'll take a look at the other items, and will learn how to post code properly! thanks so much!!!