<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body onload="do_game()">
<script>
var colors =['red','blue','green','yellow','Magenta','cyan','grey','black','brown','white','violet','indigo'];
var target;
var guess;
var count=0;
function do_game()
{
colors.sort();
target = Math.floor(Math.random() * colors.length);
do {
guess = prompt(
"I have a color on my mind\n\n" + colors +
"\n\nWhat color is it?"
)
count++;
} while (check_guess());
}
function check_guess(){
var cg= colors.indexOf(guess);
if(cg < 0)
alert("Please Enter a valid choice");
else if(cg> target)
alert("Your color is alphabetically higher than mine");
else if(cg< target)
alert("Your color is alphabetically lower than mine");
else{
alert("Congrats! You have guessed the right color\n\n" + "You took" + " " +count + " "+ "no. of guesses");
return false;
}
return true;
}
</script>
</body>
</html>
// Code goes here
/* Styles go here */