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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Boolean Values

Why is it that he didn't type var before correctGuess=true; in the first if statement?

Boolean Values.

3 Answers

Steven Parker
Steven Parker
229,644 Points

A variable can only be declared one time in a program.

On line 1 correctGuess is declared using var and initialized to false. Anywhere later in the program, like in the if statement, the variable can be reassigned by using only its name. It would be incorrect to declare it again.

Fritz-Patrick Atienza
Fritz-Patrick Atienza
5,010 Points

The logic is that correctGuess wouldn't be true until the user types in the right number, so in all other cases, the guess would false.

Jacques Retief
Jacques Retief
954 Points

Well answered, Steven Parker!