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.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Boolean Values

My console keeps printing the else statement even when i guess the correct number.

var correctGuess = false; const number = 6; const guess = prompt('guess a number between 1 and 10');

if ( +guess === number ) { correctGuess === true; }

if ( correctGuess ) { console.log('you guess the number.'); } else { console.log(Sorry the number is : ${number}); }

1 Answer

Brandon White
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi Kamarky, === is the strict equality operator, while = is the assignment operator.

In your code you never actually change the value of correctGuess to true. You simply check if correctGuess is true, which it isn’t because in the first line you set it to be false.

So in the final if...else statement the else always runs because correctGuess will always be false.

In the section of code where you’re attempting/meaning to change correctGuess to true, use the assignment operator instead of the strict equality operator.

The rest of your code is perfect. Nice job, coder.