0

Multiple if statements (an array)?

How can I get the following function to return multiple color types (not just red, but also orange, yellow, etc.)? function isRainbowColor(color){ if (color === "red"){ return true; }else{ return false; } } console.log(isRainbowColor("red")); //This works but only for one color at a time. Any suggestions?

4th Feb 2021, 1:07 AM
tristach605
tristach605 - avatar
2 Antworten
+ 1
if (['red','orange','yellow',...].includes(color)) will do the trick ;)
4th Feb 2021, 1:35 AM
visph
visph - avatar
4th Feb 2021, 1:29 AM
Ayush Kumar
Ayush Kumar - avatar