How to use math . random to get a 2 digit value? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to use math . random to get a 2 digit value?

24th Jan 2018, 3:21 AM
Swadhin Kishan
Swadhin Kishan - avatar
2 Answers
+ 2
Well, what you could do is set the range from 10 to 99, just so that any value it will return will be a 2 digit number, then get the floor value of that so that it would be a whole number. For example: document.write(Math.floor(Math.random() * 99 + 1))
24th Jan 2018, 3:56 AM
Faisal
Faisal - avatar
+ 1
thanks
24th Jan 2018, 4:09 AM
Swadhin Kishan
Swadhin Kishan - avatar