Reputation: 445
I am writing a Javascript and dont know how to form the loop
if (value < 25){
$(selector).css({ 'background': 'Red' });
} else if (value > 25 && value < 75){
$(selector).css({ 'background': 'Orange' });
}else{
$(selector).css({ 'background': 'LightGreen' });
}
else if error--> Unmatched else no if defined Where am I going wrong. Thanks
Upvotes: 0
Views: 341
Reputation: 47510
It should be
else if ((value > 25) && (value < 75))
not
else if (value > 25) && (value < 75)
EDIT
This is quite common in programming languages. You have to enclose all the conditions in parentheses.
Upvotes: 1
Reputation: 3752
if(value > 25) && (value < 75){
should be
if(value > 25 && value < 75){
Upvotes: 4
Reputation: 11041
if (value < 25){
$(selector).css({ 'background': 'Red' });
} else if (value > 25 && value < 75){
$(selector).css({ 'background': 'Orange' });
}else{
$(selector).css({ 'background': 'LightGreen' });
}
You need to have parentheses around the whole if block.
Upvotes: 0