mercredi 30 janvier 2019

How to use if-statement with randgen

I'm trying to make sure two randomly generated numbers don't match, is there a way to do this in an if-statement?


i'm fairly new to javascript and couldn't find anything that answered my question, rand2 and rand3 both pick from the same list and it would make the outcome seem odd if they matched. my code also stopped working when i put the if-statement in (if i messed that up i guess it wouldn't matter if i got an answer).

      function sentence() {
        var rand1 = Math.floor(Math.random() * 2);
        var rand2 = Math.floor(Math.random() * 12);
        var rand3 = Math.floor(Math.random() * 12);
        var rand4 = Math.floor(Math.random() * 10);
        var rand5 = Math.floor(Math.random() * 10);
        var rand6 = Math.floor(Math.random() * 10);
        //                var randCol = [rand1,rand2,rand3,rand4,rand5];
        //                var i = randGen();

        if (rand2 == rand3) {
        // whatever changes one
        } else {
        //
        }

Aucun commentaire:

Enregistrer un commentaire