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 Improving the Random Number Guessing Game

correctGuess = false?

Hey guys just wondering, why does the syntax starts off with: correctGuess = false?

Can someone explain why the correctGuess variable is set to false before we begin?

2 Answers

Devin Scheu
Devin Scheu
66,191 Points

Because if correct answer started as true the code would never run :), this is just clarifying that the variable is false to start with. :)

Yeah, thats right

Bob Sutherton
Bob Sutherton
20,160 Points

I omitted declaring it in the beginning of my program and it ran okay except that my else statement wouldn't execute. So, declaring that variable as false in the beginning is quite important indeed! Reading this thread actually helped me debug why my else statement wasn't firing.