Problems with Generate Random whole numbers with JavaScript

Good evenings to you all,
I have a question in this challenge using Math.floor and Math.random,
i just want to know why the code has a var that seems unrelated to the function ? Because in the challenge we need to accomplish this task:

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

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

function randomWholeNum() {

// Only change code below this line

return Math.floor(Math.random()* 10);

}

I will thank you so much your kind orientation on this topic,
thank you all,

Ivonne

please include challenge link, and explain what variable is not related to the challenge
I think I am missing context but I do not understand what part of the code you are asking about

Hello @Ivonne,
Var randomNumberBetween0and9 = Math.floor(Math.random()*20);

This is a function expression. To log it to the console, you will need to use the variable name declared.
e.g console.log(randomNumberBetween0and9);

hope this helps.

1 Like

Dear @ieahleen,
Good morning
I appreciate your kind reply , I want to know why we use in this challenge, the keyword var and why we call this variable randomNumberBetween0and19;
Here is the link of the freecodecamp challenge :


Thank you in advance :pray:t3:

Dear @ayarasiena,
Good morning
Thank you for your kind orientation ,
I appreciate it,
Kind regards

the variable shows an applied example of the topic of the challenge: the variable has value of a random number between 0 and 19

I think that code should be removed. It’s just confusing to have unused code as an example when the challenge text already gives an example.

I opened an issue.

2 Likes

Dear @lasjorg,
Good evenings,
Thank you so much for your reply, we appreciate it, we are making a track of javascript with mentees and mentors and some of the mentees had questions of this particular challenge , we appreciate your kindness in taking in count our question.
Have a Blessed evening, and thanks again,
Kind regards,
Ivonne