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 Combining Multiple Tests Into a Single Condition

What if I wanted the user to guess the number in between.

What if I wanted the user to guess the number in between. I wanted the user to know the answer.

For example. A randomnumber is generated "4" and i ask him to enter the number between 3 to 5?

2 Answers

Jonathan Dewitt
Jonathan Dewitt
8,101 Points
const value = 4
const x = parseInt(value - 2)
const y = parseInt(value + 2)
const guess = parseInt(prompt('Guess a value between ' + x + ' and ' + y))

if ( guess === value )
    alert('You guessed correctly!')
else
    alert('Sorry, that is incorrect.')
Theo VOGLIMACCI
Theo VOGLIMACCI
8,027 Points

Hello Akashdeep Matharu,

If i'm right, you'll learn this in the next few videos.