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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Seokhyun Wie](https://uploads.teamtreehouse.com/production/profile-photos/10732671/micro_269DA699-CEB6-43D9-AC51-AB87CBA69276.jpg)
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsRegarding the last 'if' clause
Hi Guys,
if (correctGuess) {
document.write('<p>You guessed the number!<p>');
} else {
document.write('<p>Sorry. The number was ' + randomNumber + ".</p>");
}
Why there's no true or false statement in the 'if' clause and just 'correctGuess' is placed?
var correctGuess = false;
this is the initial statement. And I think there should be clear declaration regarding correctGuess, but the program is working perfectly..why? Thanks.
3 Answers
![Jamie Reardon](https://uploads.teamtreehouse.com/production/profile-photos/9708342/micro_treehouse-mod-slack-profile-pic.jpg)
Jamie Reardon
Treehouse Project ReviewerHi Brandon, the assumption that correctGuess is equal to true is because of the default behaviour of the if statement.
// This is the same as using correctGuess == true inside the condition.
if ( correctGuess ) {
// ...
}
// We can also override the default behaviour of the if statement by using the not (!) operator like so:
if ( !correctGuess ) { // Means if not true
// ...
}
// Another way of doing this
if ( correctGuess !== true ) {
// ...
}
![Piotr Manczak](https://uploads.teamtreehouse.com/production/profile-photos/10607994/micro_20200829_211123.jpg)
Piotr Manczak
Front End Web Development Techdegree Graduate 29,253 PointsBecause correctGuess = true, so: correctGuess = 1, therefore it exist.
if( 1 ) { /*do something } I know it's weird. I guess we just have to accept this way of thinking. It's like a shortcut.
![Seokhyun Wie](https://uploads.teamtreehouse.com/production/profile-photos/10732671/micro_269DA699-CEB6-43D9-AC51-AB87CBA69276.jpg)
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsThanks again for your time :) I am already kinda used to accepting designated knowledge while learning this course, so will try. Thanks
![Piotr Manczak](https://uploads.teamtreehouse.com/production/profile-photos/10607994/micro_20200829_211123.jpg)
Piotr Manczak
Front End Web Development Techdegree Graduate 29,253 PointsThere is an assumption that it's true. It looks funny but this is correct. Your way is correct as well.
![Seokhyun Wie](https://uploads.teamtreehouse.com/production/profile-photos/10732671/micro_269DA699-CEB6-43D9-AC51-AB87CBA69276.jpg)
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsHi Piotr, So do you mean that by typing only the variable ”correctGuess”, you make an assumption that it is true? Can you explain where is the assumption? Thanks.
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsSeokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsThanks Jamie! It was helpful 👍🏻