Math.random to guess a random number? | Sololearn: Learn to code for FREE!

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));

2/1/2021 10:23:08 PM

tristach605

2 Answers

New Answer

+1

Check if loop again, And correct it to following, if (Math.floor(Math.random() * 6) ==(number)){

0

Thanks, Abhay:).