Math.random to guess a random number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Math.random to guess a random number?

function guessMyNumber(number){ if (Math.floor(Math.random() * 6)) == (number){ return "yes"; }else{ return "no"; } } console.log(guessMyNumber(3));

1st Feb 2021, 10:23 PM
tristach605
tristach605 - avatar
2 Answers
+ 1
Check if loop again, And correct it to following, if (Math.floor(Math.random() * 6) ==(number)){
1st Feb 2021, 10:32 PM
Abhay
Abhay - avatar
0
Thanks, Abhay:).
2nd Feb 2021, 1:49 AM
tristach605
tristach605 - avatar