vendredi 5 juin 2015

if..else in a function (javascript)

I'm trying to make a click function, and I want it to add +1 to win if it get number 1 and add +1 to lose if it get number 2. But I can't see whats wrong on my code..

Demo

var wins = 0;
var losses = 0;

    function cookieClick(number){
        var gamerand = Math.floor(Math.random() * (2 - 1 + 1)) + 1;
        document.getElementById("gamerand").innerHTML = gamerand;
        if(gamerand = 1){
            wins = wins + 1;   
        }else{
            losses = losses + 1;   
        }
    }

Aucun commentaire:

Enregistrer un commentaire