Tell us what’s happening:
I don’t think I understand this problem quite well, I am not able to complete 3/4 objectives of the challenge.
Your code so far
function randomRange(myMin, myMax) {
// Only change code below this line
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 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/83.0.4103.61 Safari/537.36.
Challenge: Generate Random Whole Numbers within a Range
yes I realized, can I use while loop to solve this problem, like while( result<= myMax&& result>=myMin){result=Math.floor(Math.random)}
I think this should print out the random value between myMax and myMin?
am I wrong with this approach?
You should never use a while loop for random number generation. And I suspect that loop does not do what you think it does. Your condition is not correct for what you are trying to use it for.
Math.floor(Math.random) will always give you NaN. Math.floor(Math.random()) will always give you 0.
Dumb questions can be the best way to learn. I was a beginner at one point, and I certainly don’t think less of you guys for being beginners now. Beginning is, definitionally, the first step : )
I wanted to do the same, I got a bit confused and used while loop (I know I it’s stupid) thinking that it will give me random value only when it satisfies my while condition, but It didn’t work for me.