Generate Random Whole Numbers within a Range - where am i going wrong

Tell us what’s happening:

// running tests

The lowest random number that can be generated by randomRange should be equal to your minimum number, myMin.

The highest random number that can be generated by randomRange should be equal to your maximum number, myMax.

// tests completed

Your code so far



// Only change code below this line.

function randomRange(myMin, myMax) {


var maxNumber = Math.max(myMin, myMax);
var minNumber = Math.min(myMin, myMax);
  
  return Math.floor(Math.random() + (minNumber)) - maxNumber; // Change this line
  
}

// Change these values to test your function
var myRandom = randomRange(5, 15);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range/

// Example
function ourFunction(ourMin, ourMax) {

  return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}

ourFunction(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);

You don’t need to use Math.max() and Math.min(), you already know which one is the max and which one is the min, it’s in the name of the variable

If you want to get a number between 3 and 7, what do you think your minimum can be?
Math.random() will give a number between 0 and 1, for the minimum you get 0, to which you sum the lesser number and then floor, so now the value is 3, and then you substract the max number, the values is -4
For the max number you get 0.99999, sum 3 and floor, again 3, minus 7, again -4

There is something wrong with the math here, maybe you need to think about it some more. Look carefully at the example.