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 trialJustyn Phearson
2,886 PointsCode is not working. Can't figure out why. Browser giving me an error msg.
This is my code:
let correctGuess = false;
const number = 6;
const guess = prompt("Guess a number between 1 and 10.");
if (+guess === number) {
correctGuess = true;
}
if (correctGuess === true) {
console.log("You guessed the number!");
} else {
console.log(`Sorry, the number was ${number}.`);
}
Justyn Phearson
2,886 PointsThe first prompt box won't even pop up.
1 Answer
Jeff Muday
Treehouse Moderator 28,722 PointsGood job, you are showing some good instincts at programming JavaScript!
Remember: when making the comparison of guess
and number
, guess
is a string and number
is an integer. You can make this work using a less strict ==
operator rather than the strict ===
operator.
Also remember to use back-tick quote marks in your else
section for it to be syntactically correct.
Other than that, it looks great!
let correctGuess = false;
const number = 6;
const guess = prompt("Guess a number between 1 and 10.");
if (guess == number) {
correctGuess = true;
}
if (correctGuess === true) {
console.log("You guessed the number!");
} else {
console.log(`Sorry, the number was ${number}.`);
}
Justyn Phearson
2,886 PointsJustyn Phearson
2,886 PointsThis is the error being given by the browser when I try to run the code:
port-80-42nqrducsm.treehouse-app.com/:10
GET http://port-80-42nqrducsm.treehouse-app.com/booleans.js net::ERR_ABORTED 404 (Not Found)