I am trying to compare each element of an array with the user input to generate a message if the user's input doesn't match with any element of the array. The code I use to do is below.
var guess_input;
var finished = false;
var colors = ["Aqua", "BurlyWood", "Cornsilk", "DarkGrey", "DarkRed", "Indigo", "LightGrey"];
while (!finished) {
guess_input = prompt("I'm thinking of one of these colors:\n\n" + "Aqua, BurlyWood, Cornsilk, DarkGrey, DarkRed, Indigo, LightGrey" + "\n\nWhat is the color I'm thinking of?");
finished = check_guess();
}
}
function check_guess() {
if (guess_input != colors[0] || guess_input != colors[1] || guess_input != colors[2] || guess_input != colors[3]) {
alert("Sorry, I don't recognize that color!\n\n" + "Please try again.");
return false;
}
}
the problem with this code is that if I only select one element from array, it works perfectly fine. but when I use 'OR' operator, it doesn't work. Is there any better way to do this? I am new with java script.
Thanks!