Mano
Mano

Reputation: 445

What is wrong with my IF logic?

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

Answers (3)

CharithJ
CharithJ

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

Kyle W
Kyle W

Reputation: 3752

if(value > 25) && (value < 75){

should be

if(value > 25 && value < 75){

Upvotes: 4

Martin
Martin

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

Related Questions