Tell us what’s happening:
Dear All,
Good afternoons,
I have a question about the following function:
I do understand the usage of Math.floor and Math.random but i don´t understand this part specifically:
(ourMax - ourMin + 1 ) + ourMin;
i know the ranges are ourMax and ourMin but what does the + 1 means ? and why we add a + ourMin?
I will appreciate and thank you all so much all the advises and orientation you can provide,
thank you all in advance for your kind reply,
Regards,
Ivonne
Your code so far
// Example
function ourRandomRange(ourMin, ourMax) {
return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}
ourRandomRange(1, 9);
// Only change code below this line.
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 1 )) + myMin
}
// Change these values to test your function
var myRandom = randomRange(5, 15);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
.
Challenge: Generate Random Whole Numbers within a Range
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range