Generate Random Whole Numbers with JavaScript Problem

Hello Everyone,

what is wrong with my code? I am not getting the output. Its showing

Your code so far

var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function randomWholeNum() {

  // Only change code below this line.
 var random = Math.floor(Math.random() * 10);
  return random;

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8.

Link to the challenge:

This isn’t your fault, freeCodeCamp is being a little too strict when it shouldn’t.

To fix the issue, don’t use a variable and just return the result immediately. Again, your code does work but freeCodeCamp’s checks can’t figure that out.

If your code was

var cat = "dog";
return cat;

You’d change it to

return "dog";

To make freeCodeCamp’s checks happy. Both of these do the same thing though.

Your code runs fine for me and passes all the tests. You may need to just refresh your browser and run the tests again.

1 Like

Thank You everyone. Now its working fine.