It is saying that the below code doesn’t satisfy this requirement: You should have multiplied the result of Math.random by 10 to make it a number that is between zero and nine.

Your code so far

function randomWholeNum() {
// Only change code below this line
var x = Math.random();
var y = x*10;
z = Math.floor(y);
return z;
}

Your browser information:

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

Challenge: Generate Random Whole Numbers with JavaScript

Right. The only problem with the code you posted is that the variable z isn’t declared. With that fixed, it will work. It fails the test because your solution is different enough from the expected solutions that the tests don’t recognize it. You can move on to the next challenge. For most functions, freeCodeCamp is able to test the results, but that doesn’t really work with random numbers.

I know why its getting an error on your challenge.

The way you do it in the screenshot its correct by creating the 3 variables to output the result, the result of generate random whole numbers, and this is correct to do it too.

function randomWholeNum() {
var x = Math.random();
var y = x * 10;
var z = Math.floor(y);
return z;
};
var result = randomWholeNum();
console.log(result);

But i think the part that you are missing, its that on the challenge it states that you must follow the same logistic of code:

(Note) this paragraph its on the challenge. This line of code must be followed in order to work.
Putting everything together, this is what our code looks like:

// This line of code must be exactly in your code.
Math.floor(Math.random() * 20);

So they multiply the Math.random() * 10;

That is what they want you to do on challenge, because if you do the same code as above it means that the challenge its programmed to identify same code structure, and if does not meet the criteria code then wont work.
So you should have something like this to work.

function randomWholeNum() {
// Only change code below this line
var random = Math.floor(Math.random() * 10);
return random;
};
var result = randomWholeNum();
console.log(result);

Hope this can help clear the challenge a bit more. Happy coding