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.
2 Answers

Steven Parker
215,984 PointsYou're quite right that this job can be done with only one "if", and good eye for spotting it!
But the purpose of the lecture is to show how boolean variables can be used, and the code shown gives a clear example. As a "best practice" developer, you'll employ your skills to create code that's both clear and efficient, but in the courses you can expect the teachers to occasionally forgo efficiency when illustrating a particular principle.

Doron Geyer
Full Stack JavaScript Techdegree Student 13,884 PointsHi , quite new to programming ( my first programming ever doing this course) could you provide an example of how you would reduce this to a single if statement?
Cheers, Doron

Doron Geyer
Full Stack JavaScript Techdegree Student 13,884 Pointsvar correctGuess = false;
var randomNumber = Math.floor(Math.random() * 6 ) + 1;
console.log(randomNumber);
var guess = prompt('I am thinking of a number between 1 and 6. What is it?');
if (parseInt(guess) === randomNumber ) {
correctGuess = true;
document.write("you guessed the correct number");
} else{
document.write("your guess was incorrect")
}
I assume like this?

Steven Parker
215,984 PointsYes, good job. And now you don't need "correctGuess" anymore and can omit it from the code.
Kishan P
9,921 PointsKishan P
9,921 PointsThanks man!