mercredi 26 juillet 2017

Lottery with Supernumber

I came across the challenge of building a random numbers generator for the lottery. 6 numbers, between 1 and 49, none of which appears twice, in ascending order. One 7th number, the superseven, not sorted, can't be one of the previous numbers.

    <script type="text/javascript">

    const numb = new Array ();
    for ( var i=0; i<6; i++ ) {
    numb[i]= Math.floor (49 * Math.random()) + 1;

    //compare to existing numbs
    for ( var k=0; k < numb.length - 1; k++ )
    {
        if (numb[i] == numb[k] ) {i--; break;}
    }



}
    let supNumb = new Array();
    supNumb = Math.floor (49 * Math.random()) + 1;
    for (var s=0; s<=1; s++ ) {
        // compare supNumb to numb
        for ( var t=0; t < numb.length - 1; t++ )
        {
            if (supNumb == numb[t] ) {s--; break;}
        }
    }




// SORT & DISPLAY NUMBERS 
function sort (a, b) {
    return a-b;
}

numb.sort(sort);
document.write("<p> " + numb );
document.write("<h4>" + "SuperSeven: "+ supNumb);

</script>

I know by trying the super seven (supNumb) is still giving out same numbers as in numb. I can't get it to work and can't find anywhere this being mentioned.

Somebody here can look over it and let me know how I can compare supNumb to numb?

Is this even the right structure?

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire