I want to check in this guessing game if the color the user inputs is in the array list or not. but when u put a color that is in the list it keeps saying it isn't
var guess_input;
var target;
var colors = ["blue", "cyan", "gold", "gray", "green", "magenta", "orange",
"red", "white", "yellow"
]
var finished = false;
var guesses = 0;
var pos;
function do_game() {
var random_number = Math.floor(Math.random() * (colors.length - 1));
target = colors[random_number];
while (!finished) {
guess_input = prompt("I am thinking of one of these colors: \n\n" + colors.join() +
"\n\n What color am I thinking of?");
guesses++;
finished = check_guess();
}
}
function check_guess() {
if (colors.indexOf(guess_input) > -1) {
alert(
"This is not a color from the list ! Please pick a color from the list\n\n"
);
return false;
}
}