Generate Random Whole Numbers with JavaScript...something is missing

Generate Random Whole Numbers with JavaScript...something is missing
0.0 0

#1

Hi,

I wonder what is wrong with my code. Everything seems to be right except one thing: “The result of randomWholeNum should be a whole number.”

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

function randomWholeNum() {

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

#2

Look closely what are you returning from function :slight_smile:


#3

I tried return Math.floor(); and then I tried return randomWholeNum(); but they don’t work.


#4

With a slight change…


#5

Thank you. Now it worked. But why it did not work with return randomWholeNum(); ?


#6

You would create an infinate loop.