Tell us what’s happening:
Describe your issue in detail here.
Hi so I understand the logic behind the formula used in the challenge but I do not understand this part:
(max - min +1)
from what I’ve read on other posts its seems as if the min is being subtracted from the max before 1 is added to the min. Does BODMAS not apply in Javascript or am I confused by something
Please help .
Thanks.
**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
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
Challenge: Generate Random Whole Numbers within a Range
Addition and subtraction execute from left to right, just like standard mathematical order of operations. max - min + 1 is the same as max + 1 - min and 1 + max - min.
Okay I get that but if for example myMax=15 and myMin=5, I will get 11 from this order of operations, if math.random() gives me a number between 0 and 1(not inclusive), how is it that the formula never gives me 15 as an answer if we get 11 x 0.99 for example which the answer when put in math.floor returns 10 and we then add the myMin to it which is 5?
Oh okay that makes much more sense, Thank you very much. I thought the maximum was excluded from the possible outcomes and that’s why I couldn’t wrap my head around it.