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

Maja Divkovic
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Maja Divkovic
Front End Web Development Techdegree Graduate 13,920 Points

True or False

Could someone please help me, my outcome is always showing "Sorry, the number was 6."

What am I doing wrong?

let correctGuess = false; const number = 6; const guess = prompt("Guess a number between 1 and 10.");

if ( guess === number) { currectGuess = true; }

if (correctGuess) { console.log('You guessed the number!'); } else { console.log(Sorry. The number was ${number}.); }

3 Answers

Steven Parker
Steven Parker
210,475 Points

If the answer matches, a new global variable "currectGuess" (with 2 "u"s) is created and set to true.
But the variable used to control the output is "correctGuess" (with an "o").

Also, a comparison with the type-sensitive operator "===" will never consider a string (as prompt gives) to match with a number. You could use the standard comparison "==" to allow the system to perform a conversion, or you could do it explicitly.

As mentioned in the video, another way to write this code would be to simply add a + in front of the variable guess in the conditional statement because you need to convert the string value returned by prompt to a number value in order to achieve your desired results. Ex: if ( +guess === number ) { correctGuess = true; }

Also, your last line of code should include a template literal Ex: else { console.log(Sorry. The number was ${number}.); }