Complex comparisons

Complex comparisons allows you to create scripts that have more values included or allow a specific range of values to return true.


if ((NumberOne > 5) && (NumberOne < 15)) {
     document.write("Right number!");
}
else {
     document.write("Wrong number!");
}

The comparison is saying that if NumberOne is greater than 5 and less than 15 then the text “Write number!” will be written. Otherwise, “Wrong number!” will be written.

The comparison can be as complex as you want or need.


var NumberOne = 4;
if ((NumberOne > 5) && (NumberOne < 15) || (NumberOne == 25)) {
document.write("Right number!");
}
else {
document.write("Wrong number!");
}

The comparison now will return true if the variable NumberOne is greater than 5 but less than 15 or it can be 25.

Leave a Reply