Skip to content
Advertisement

Why doesn’t my if statement work with (red || green || blue) > 255

here’s my code:

JavaScript

I’m having problems in this line:

JavaScript

bad operand types for binary operator ||. Any ideas how to fix it? My code is very simple so I believe I don’t have to explain anything. I just don’t understand why I can’t check if integer is greater than 255 for e.g. Thanks on advance!

Advertisement

Answer

You need to test each variable seperately:

JavaScript

However, for good code I’d write a function:

JavaScript

… which you could then call as:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement