Can't solve this one: Generate Random Whole Numbers within a Range

Tell us what’s happening:

So i tried to get over it
But changing the last line to myMax doesn’t work but, i did set it to equal to. Then I tried myMin but, another failure again.

Your code so far

function randomRange(myMin, myMax) {
// Only change code below this line
return Math.floor(Math.random() * (myMin - myMax + 1) >= myMin);

// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.

Challenge: Generate Random Whole Numbers within a Range

Link to the challenge:

Why are you calculating the floor of a Boolean?

You are making a comparison here, so it will evaluate to true or false.

1 Like

Why do you have a comparison in there? You are converting a portion of your work to a Boolean which is making a mess of your code.

Can you explain this logic?

Take a look at the example in the challenge:

Math.floor(Math.random() * (max - min + 1)) + min

There are no comparison operators used. All you have to do is substitute the variable names.

Of course the texts ask me to: and is less than or equal to myMax , inclusive.
The >= meant less then or equal to.
and the myMax is what we needed to check.
But, when I entred that one it did’t work So I thought it might be JS way of reading things and needed to use minMax instead to compare it.

Did you see

Here’s the formula we’ll use. Take a moment to read it and try to understand what this code is doing:

Math.floor(Math.random() * (max - min + 1)) + min
1 Like

You should read through the challenge description again. It shows you how to randomly generate a number within a range of two numbers. The “range” of two numbers means greater or equal to a lower number and less than or equal to a higher number. In this case, the lower number is myMin and the higher number is myMax.

1 Like

That’s not how>= works. What does >= actually do?

Yes the comparison operator doesn’t belong there. I think for the purpose of this exercise you can assume that myMax is always going to be greater than or equal to myMin.

1 Like

As @sgedye says, for the purpose of this exercise assume myMax is ALWAYS greater than myMin.
Later, as real a developer, you’ll want to add in some validation code before just “always assuming”.

1 Like