mardi 15 août 2017

How to add custom rules to a calculator?

I'm making a outfit randomizer. But I would like to add some rules to it to prevent weird outfits like a white tie on a white shirt. Or any tie on a graphic tee. Or wearing a turtleneck over a shirt.

This is the code @obsidian-age (thanks buddy) help me with, so far:

        var shirts = ["White", "navy", "light blue", "gray"];
        var pants = ["black", "navy", "gray"];
        var ties = ["red and blue squares", "purple", "white", "red"];

        var random_shirt = shirts[Math.floor(Math.random()*shirts.length)];
        var random_pants = pants[Math.floor(Math.random()*pants.length)];
        var random_tie = ties[Math.floor(Math.random()*ties.length)];

        document.write( " shirt: " + random_shirt + " pants: " + random_pants + " tie: " + random_tie);

I know it's done with if's and else's, but I don't know how.

Please forgive my JS illiteracy. I learned it but never actually used it. Until now.

Thanks




Aucun commentaire:

Enregistrer un commentaire