Created
July 1, 2022 15:47
-
-
Save ashraf267/3395393e18236251ca6d7a8ce342cf5e to your computer and use it in GitHub Desktop.
custom JS code to search through an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let colors = ["red", "green", "blue", "yellow"]; | |
let favColor = "pink"; | |
(function check() { | |
let output = 0; | |
for(color in colors) { | |
// console.log(colors[color]); | |
if(colors[color] == favColor) { | |
output = "I found your favorite color, color " + colors[color]; | |
break; | |
} | |
} | |
isNaN(output) ? console.log(output) : console.log("Unknown currency"); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment