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 trialSal Sal
47 PointsIn the If at the end.Why do we not add correctGuess= true.?
In the If statement in the end why do we not do it like this: if (correctGuess= true) { document.write("<h1> You Guessed the number right.</h1>"); document.write("It took you " + guessCount + " tries to guess the correct number " + randomNumber + "."); } else if (correctGuess= false){ document.write("<h1> Sorry. You did not guess the number.</h1>") }
4 Answers
Patrik Horváth
11,110 PointsCheck your code and check IF statment
= is for Asign value to
Example :
var a = 2;
== is for equal check :)
var a == 2 -> this return true or false
so you cant do this
if (correctGuess= true)
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsHere is another way of doing it:
EDIT: if you just need to check if a variable is true or truthy, then you don't really need to say == true, == false etc..
if (correctGuess) { // same as saying "correctGuess == true"
// do something
} else if (!correctGuess) { // same as saying "correctGuess != true"
// do something
} else {
// do something
}
Rhys Kearns
4,976 PointsExplain your code as someone who is new would have no idea :)
Rhys Kearns
4,976 Points:D Perfect now he knows what the abbreviations mean :D
Sal Sal
47 PointsSo if I add:
if (correctGuess === true).
Would that be right.?
Brian Prouty
1,792 PointsI think I am confused about the same thing, I am wondering why when you call the if (correctGuess) later in the code why is that not equivalent to correctGuess = false; at the top? I was under the impression that the only way to call 'correctGuess = true' is either typing it out like that or '(! correctGuess)'... can anyone help explain this??