Basic JavaScript - Generate Random Whole Numbers with JavaScript

Tell us what’s happening:
when I run this I get

  • Failed:The result of randomWholeNum should be a whole number.

  • Passed:You should use Math.random to generate a random number.

  • Passed:You should have multiplied the result of Math.random by 10 to make it a number that is between zero and nine.

  • Passed:You should use Math.floor to remove the decimal part of the number.

I have tried many things and I am still not passing this part, nor do I understand what I am missing. Finding java harder to understand than HTML. Any hints would be appreciated.

Your code so far

function randomWholeNum() {

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Generate Random Whole Numbers with JavaScript

Link to the challenge:

You’re simply returning the wrong thing.
Your return statement should explicitly return a value of some kind.
So why not try just returning what you have in the line above?

function randomWholeNum() {

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

I still get the same answer.

When I said ‘the line above’ I meant this.

function randomWholeNum() {

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

ok that did work, oh i see we are returning the result of Math.floor(Math-random()*10);
daahh now I see.
thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.