Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,594 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
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
Front End Web Development Techdegree Graduate 25,171 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
Full Stack JavaScript Techdegree Graduate 21,594 PointsThanks again for your time :) I am already kinda used to accepting designated knowledge while learning this course, so will try. Thanks

Piotr Manczak
Front End Web Development Techdegree Graduate 25,171 PointsThere is an assumption that it's true. It looks funny but this is correct. Your way is correct as well.

Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,594 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,594 PointsSeokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,594 PointsThanks Jamie! It was helpful 👍🏻