Unexpected result in the console while testing output of random numbers

Tell us what’s happening:

I am struggling to understand the output on the console when I check this answer. I am expecting to see random numbers between 1 and 6. However I see double digit numbers in the answer.

Your code so far


function randomRange(myMin, myMax) {
// Only change code below this line
console.log(Math.floor(Math.random() * (myMax - myMin + 1) + myMin));
// Only change code above this line
}

randomRange(1, 6);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Generate Random Whole Numbers within a Range

Link to the challenge:

hey @Martin_Donohoe,

this will console.log all the test results too, and yours randomRange(1, 6); will be the first number at the top of the list.

Thanks for the quick reply. Sorry could you expand your answer. I am only expecting to see a random number from 1 to 6.

Are you saying that the code is generating more than one number or are you saying that the “console” is showing the results of previous tests?

The console output is confusing me.

Is there a better way to test my code than using the console on the test page?

@Martin_Donohoe hey,

Its all the tests that fcc are running, so it will console.log for everytime the function has ran for example if you done this…

function randomRange(myMin, myMax) {
  // Only change code below this line
  console.log(myMax)
  return 0;
  // Only change code above this line
}

it will console.log a load of 15s because thats what all the ffc tests are using for their max number,
it shouldn’t be like this i dont think, i get how it would confuse people so i dont know why they do it like this, so if you ran this…

function randomRange(myMin, myMax) {
  // Only change code below this line
  console.log(myMax)
  return 0;
  // Only change code above this line
}

randomRange(3, 60)

It will be 60 at the top which is what your testing, then followed by a load of 15s which fcc is testing.

1 Like

@biscuitmanz Thanks for that. I wasted a lot of time on that question. I kept making changes because I thought all the output was coming from my code.

1 Like

yeah i dont think its like this on every test, there might a bug on this test maybe that makes the tests run without pressing the run the tests button

@biscuitmanz

You were right. I tried it in the next test area and got just a single result using the console.

thanks again.

1 Like

instead of putting the console log inside the function, put the function call inside the console log

1 Like

Thank you . I will remember that for my next lesson.