In this fun guessing game, I am testing to see if the color entered by the user is in the array list or not. But oddly enough, even when the correct color is input, it keeps saying that 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;
}
}