mercredi 17 février 2016

If statement not working, probably something basic gone wrong

I was testing a script and had a problem with a specific part. I isolated the part that was giving me problems.

var target_army = "0";

function test(){
    if (target_army == "0") {
        var target_army = "1";
        alert (target_army);
    } else {
        alert ("nope");
    }
}

The function runs the alert "nope nope" while target_army should be 0. The part

var target_army = "1";
alert (target_army);

runs fine but with the addition of the if statement it goes wrong. Does anyone have an idea where I dun-goofed?

Aucun commentaire:

Enregistrer un commentaire