I'm practicing html, css and javascript, and I have been trying to run this code but ended up failing to do so. I couldn't figure out where I went wrong. All your efforts are appreciated.
<!doctype html>
<html>
<head>
<title>Example of a function</title>
<script>
var colors = {
"blue", "green", "red"
};
var guessColor;
var guesses = 0;
var finished = false;
var target_index;
var targetColor;
function do_game() {
var randomNo = Math.random() * 3;
var randomNo_integer = Math.floor(randomNo);
target_index = randomNo_integer;
targetColor = colors[target_index];
while (!finished) {
guessColor = prompt("I am thinking of one of these colors:\n\n" +
"Blue, Green, Red\n\n" +
"What color am I thinking of?");
if (guessColor.toUpperCase() == targetColor.toUpperCase())
finished = true;
}
document.body.style.backgroundColor = guessColor.toLowerCase();
}
</script>
</head>
<body onload="do_game()">
</body>
</html>