Created
April 23, 2013 23:38
-
-
Save jennojenno/5448370 to your computer and use it in GitHub Desktop.
Finding whether a value inputted by user exists in the given array
This file contains 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
var fruits = ['apples', 'pears', 'bananas']; | |
console.log("Enter in a fruit name"); | |
process.stdin.on('data', function(fruit) { | |
var fruitName = fruit.toString().replace("\n", ""); | |
if (fruits.indexOf(fruitName) >= 0 ) { | |
console.log("The value has been found in the array"); | |
process.exit(); } | |
else { | |
console.log("Value not found"); | |
process.exit(); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment