/*I am attempting to run a color guessing game in my browser, but when I try opening the code in Chrome, it doesn't work. Any suggestions or ideas would be greatly appreciated.*/
var colors = ["Aqua", "Black", "Blue", "Brown", "Coral", "Crimson", "Cyan","Fuchsia", "Gold", "Gray", "Green"];
var target;
var guess_input_text;
var guess_input;
var finished = false;
var guesses = 0;
function do_game() {
var random_number = Math.random() * colors.length - 1;
var target_index = Math.floor(random_number);
target = String(colors[target_index]);
//What could be causing this code not to function properly in Chrome? Any insights?
while (!finished) {
guess_input_text = prompt("I am thinking of these colors:\n\n"
"Aqua, Black, Blue, Brown, Coral, Crimson, Cyan, Fuchsia, Gold, Gray, Green\n\n"
"What color am I thinking of?");
guess_input = String(guess_input_text);
guesses += 1;
finished = check_guess();
}
}
/*Am I structuring my if statement correctly here? Am I structuring my if statement correctly here?*/
function check_guess(){
if (guess_input != "Aqua"||"Black"||"Blue"||"Brown"||"Coral"||"Crimson"||"Cyan"||"Fuchsia"||"Gold"||"Gray", "Green") {
alert("Sorry, I don’t recognize your color.\n\nPlease try again.");
}
if(guess_input < target){
alert("Sorry, your guess is not correct!\n\nHint: your color is alphabetically higher than mine.");
return false;
}
if(guess_input > target){
alert("Sorry, your guess is not correct!\n\nHint: your color is alphabetically higher than mine.");
return false;
}
alert("Congratulations! You have guessed the color!\n\n"
"It took you " + guesses + " to finish the game!\n\n"
"You can see the color in the background.");
return true;
}