Tell us what’s happening:
The goal of the assignment is to generate random number using Math.random() x whole number between 0-9 (i.e 0 and 9 shouldn’t be generated)
So my initial solution was as follows:
function randomWholeNum() {
return Math.floor(Math.random()*9);
}
However, the requirement stated that I should be multiplying by 10.
Since, 0< Math.random<1,
(multiplying by 10):
0<math.Random x 10< 10 (i.e. 9.99999999 is one of the possible random float)
Followed by rounding down to nearest whole number.
0< math.floor(math.Floor x 10 ) =< 9
Hence, wouldn’t it infringe on the desired condition of generating any random number between 0 and 9?
Please do advise.
Many thanks in advance.
Your code so far
function randomWholeNum() {
// Only change code below this line
return Math.floor(Math.random()*10);
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Generate Random Whole Numbers with JavaScript
Link to the challenge: