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

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Do we need to create the guessLess variable? Can't we just use the previous guessMore variable instead?

I was wondering why we create the guessLess variable inside the second else if statement, when we already have created a new variable called guessMore inside the first else if statement? Can't we use the guessMore variable for both else if statements? And tweak the prompt question for the user input. Even the name sounds pretty logic with the "More" word since we want the player to guess "more".

1 Answer

Hi. You have to create a new variable to each user try. Why u have to do it? as u saw in the video each time the user gets a prompt dialog and he the input he send being stored inside a variable in order to make some conditional checks.

so for try number one, lets say the user enters the wrong random number, this value being assigned to the "guessMore" variable and he is being stored there.

in the second attempt You have to create another variable in this case "guessLess" in order to store the second random number the user has been guessed.

You can't store 2 values inside a variable, unless it's an array, nevertheless for each attempt u need to perform some conditional checks, and for each attempt u need to have a variable that stores the input from the user.

hope this helps