Tell us what’s happening:
Your code so far
function randomRange(myMin, myMax) {
// Only change code below this line
return **Math.floor(Math.random() * (myMax - myMin + 1)) + myMin**
;
// Only change code above this line
}
console.log(randomRange(5, 10))
console.log(randomRange(5, 10))
console.log(randomRange(5, 10))
console.log(randomRange(5, 10))
console.log(randomRange(5, 10))
console.log(randomRange(5, 10))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 Edg/87.0.664.41
.
Challenge: Generate Random Whole Numbers within a Range
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
HI @viveksuman393 !
Welcome to the forum!
You have added some extra stuff to the solution.
viveksuman393:
**Math
and
viveksuman393:
Min**
If you delete those extra ** then the test should pass.
I am also going to link the mdn resources for Math.random() and Math.floor() which do a good job of explaining how it works.
The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The...
Read up on what the two functions (Math.floor and Math.random) do, then try replacing the variables with numbers (on paper, write it down, don’t guess).
See what plugging different numbers in does.
1 Like