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 trialKevin Lewis
Front End Web Development Techdegree Student 9,667 PointsRecived a syntax error and I'm not sure why
Don't know what I'm missing from theses statements.
var correctGuess = false
var randomNumber = Math.floor(Math.random() * 10)+1
var guess = prompt("What is the number I am thinking of? It's between 1 and 10")
if (parseInt(guess) === randomNumber {
correctGuess = true;
}
if (correctGuees) {
alert('This is true');
} else {
alert('This is false');
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Kevin Lewis
Front End Web Development Techdegree Student 9,667 PointsThanks for the help. I did these corrections and it told me it couldn't find the varaible correctGuess for some reason even though it was defined.
Michael Lauridsen
10,321 PointsThat is because of a typo. You are checking for correctGuees with two e's instead of two s :) I've made that mistake quite a lot!
Anders' solution should work:
var correctGuess = false
var randomNumber = Math.floor(Math.random() * 10) + 1
var guess = prompt("What is the number I am thinking of? It's between 1 and 10")
if (parseInt(guess) === randomNumber) {
correctGuess = true;
}
if (correctGuess) {
alert('This is true');
} else {
alert('This is false');
}
1 Answer
Steven Parker
231,248 PointsDid any of you guys read the instructions?
This challenge is super simple, It doesn't involve any prompts, number conversion, Math funcitons, random numbers, or program logic.
The instructions say, "Place a Boolean value between the parenthesis for the condition in this conditional statement." So all you need to do is place one single word between the parentheses of the provided code to pass the challenge.
And if you don't put in the right word the first time, it will even give you a hint telling you what to use!
Anders Prytz
26,193 PointsAnders Prytz
26,193 PointsHi
First of all, you need to end all lines in the beginning with a semicolon, as well as you are missing a end parenthesis in the first if statment.
This would solve your problem:
var correctGuess = false; var randomNumber = Math.floor(Math.random() * 10)+1; var guess = prompt("What is the number I am thinking of? It's between 1 and 10");
if (parseInt(guess) == randomNumber) { correctGuess = true; }
if (correctGuess){ alert('This is true'); }else { alert('This is false'); }