0
私は色推測ゲームを作成するように割り当てられています。アイデアは、プレイヤーが色を推測する必要があり、正しく推測すると背景が変わるということです。しかし、私はゲームを起動してブラウザで動かすのに苦労しています。私はコンソールを見て、強調表示されているエラーを理解していません。色推測ゲーム
<body>
<script type="text/javascript">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
window.onload = game()
var colours=["blue","purple","pink","red","green","yellow"];
// var target_index
var target
var guess_input
var finished = false;
var guesses = 0;
function game() {
var random_colours = Math.floor(Math.random()* colours.length);
target = random_colours;
while (!finished) {
guess_input = prompt ("I'm thinking of one of these colours\n" + colours + "\n What colour am I thinking of?")
guesses += 1;
finished = check_guess();
}
}
function check_guess() {
if (guess_input == isNaN) {
alert ("I don't recgonise\n" + "Please try again");
return false;
}
if (guess_input > target) {
alert ("Your colour is alphabetically higher than mine\n" + "Please try again");
return false;
}
if (guess_input < target) {
alert ("Your colour is alphabetically lower than mine\n" + "Please try again");
return false;
}
if (guess_input == target) {
alert ("Congratulations, the colour was" + target + "it took you" + guesses + "to finish the game!" "You can see the color in the background");
return true;
}
}
</script>
</body>
</html>