Malj72
9/11/2017 - 10:27 AM

Generate a random number between 0-10 until you get desired number

Generate a random number between 0 and 10 until you get desired number. How many tries did it take?

function check(numb) {
    var i = 0;
        numbRand = 0;
    while (numbRand !== numb) {
        numbRand = Math.floor(Math.random() * 11);
        i++;
        console.log(numbRand);
    }
    return `It took ${i} time(s) to reach ${numb}.`;    
}

console.log(check(7));