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 trial
Eric Thompson
9,858 PointsAny idea why code won't execute?
For the "Do While Loops" Javascript tutorial I have an exact mirror of the code the instructor has in the video, but when I save and preview my code nothing happens!
In the Javascript console, I am seeing an "Uncaught Syntax Error: Unexpected token =" for Line 14. Please see my code below:
var randomNumber = getRandomNumber(10);
var guess;
var guessCount = 0;
var correctGuess = false;
function getRandomNumber( upper ) {
var num = Math.floor(Math.random() * upper) + 1;
return num;
}
do {
guess = prompt('I am thinking of a number between 1 and 10. What is it?');
guessCount +=1;
if (parseInt(guess) ==== randomNumber) {
correctGuess = true;
}
} while ( ! correctGuess )
document.write('<h1>You guessed the number!</h1>');
document.write('It took you ' + guessCount + ' tries to guess the number ' + randomNumber);
Any feedback would be much appreciated. Thanks! BTW, I am using Chrome as my browser. Also tried Safari, but still running into the same problem.
2 Answers
Colin Marshall
32,861 PointsYou have 4 equal signs in a row in your if statement on line 14. Change it to 3 equal signs.
if (parseInt(guess) === randomNumber) {
correctGuess = true;
}
Eric Thompson
9,858 PointsNope. It's crazy, I know. When I try to preview the code the page is still blank, and in the Javascript console it still says "Uncaught Syntax Error: Unexpected token =". Also still showing script.js:14
Oddly, when I look at line 14 in the console, it's not highlighting anything out of the ordinary (like it did when I had the 4 equal signs).
Eric Thompson
9,858 PointsEric Thompson
9,858 Points(Facepalm) I completely missed that, lol. Thanks for pointing that out.
However, I did remove one of the equal signs and am still running into the same problem:
Colin Marshall
32,861 PointsColin Marshall
32,861 PointsI'm confused when you say you're "running into the same problem." You should at least be getting a different error message.