Reputation: 225
alert(Tag); // Tag shows it is set to 0 (ZERO) which is less than 10.
if ( Tag < 10) { alert("adding.."); Tag=Tag+10; }
else { alert("Fail"); }
alert(Tag);
// alert shows me "fail" // and alert shows "0"
So, it says its zero, if statement DOES NOT show it less than 10, and it remains zero.... What am I doing wrong??
Upvotes: 3
Views: 162
Reputation: 558
http://jsbin.com/honixenopo/edit?js,console
I suspect tag is set to a string with the capital letter o as a type-o.
Upvotes: 0
Reputation: 9939
You need to define Tag
first. I am also just incrementing Tag
by 1. This can be changed if needed.
var Tag = 0;
if ( Tag < 10) {
alert("adding..");
Tag++;
}
else {
alert("Fail");
}
alert(Tag);
Upvotes: 1
Reputation: 6251
This works when Tag is actually the number 0.
<script>
var Tag = 0;
alert(Tag); // Tag shows it is set to 0 (ZERO) which is less than 10.
if ( Tag < 10) { alert("adding.."); Tag=Tag+10; }
else { alert("Fail"); }
alert(Tag);
</script>
Where do you assign Tag its value?
Upvotes: 1