I’m having a problem handling some numbers from a json request. Based on the results I’m trying to output some various bits of HTML. Specifically the problem is when I come to check whether a number is greater than -1, but less than 6. Code excerpt is as follows…
else if(parseInt(myvariable, 10) < -1) {
//this is where one thing happens
}
else if(parseInt(myvariable, 10) > -1) {
//Something else happens here
}
else if(parseInt(myvariable, 10) > 6) {
//This is where the third thing should happen, but doesn't?
}
It seems that despite the value being 7 or 70 the second ‘else if’ is as far as it gets.
Is there a way that I can check that the number is more than -1 but less than 6 so that it moves on to the next conditional statement.
I’m guessing that (like my previous question) there’s a very simple answer so please excuse my naivety.
Thanks in advance.
Conditions are executed only until one is found to be true.
In other words, you need to re-jig their order or tighten them to make your current order work.
7 is above -1, so the second condition resolves to true. So for 7, the 3rd condition is never needed.