min
and a maximum number max
.
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
randomRange
that takes a range myMin
and myMax
and returns a random number that's greater than or equal to myMin
, and is less than or equal to myMax
, inclusive.
randomRange
should be equal to your minimum number, myMin
.
testString: assert(calcMin === 5, 'The lowest random number that can be generated by randomRange
should be equal to your minimum number, myMin
.');
- text: The highest random number that can be generated by randomRange
should be equal to your maximum number, myMax
.
testString: assert(calcMax === 15, 'The highest random number that can be generated by randomRange
should be equal to your maximum number, myMax
.');
- text: The random number generated by randomRange
should be an integer, not a decimal.
testString: assert(randomRange(0,1) % 1 === 0 , 'The random number generated by randomRange
should be an integer, not a decimal.');
- text: randomRange
should use both myMax
and myMin
, and return a random number in your range.
testString: assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), 'randomRange
should use both myMax
and myMin
, and return a random number in your range.');
```