Generate Random Whole Numbers with JavaScript Issue

Tell us what’s happening:

Not sure where i’m wrong here - do i need add var randomWholeNum = before my code?

Your code so far


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

function randomWholeNum() {

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

}

Your browser information:

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

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

1 Like

Try this:

function randomWholeNum() {
    return  Math.floor(Math.random() * 10);
}

Or this

function randomWholeNum() {
    let num = Math.floor(Math.random() * 10);
    return  num;
}

You need to return the whole line or set it to a variable and return that.
Math.floor returns the whole function for the floor().

2 Likes

Thank You so much! That worked!