사용자가 추측해야하는 임의의 색상을 생성하는 게임을 만들고 있습니다. 이것은 첫 번째 부분이지만 페이지를 확인하려고하면 onload 메시지 만 표시됩니다. 차단기를 켰어. 나는 기능을 불렀지 만 여전히 아무것도 말하지 않았다.함수가 호출 된 후에도 경고 및 프롬프트가 작동하지 않습니다.
<!doctype html>
<html>
<head>
<title>Guess the Color Assignment 2 Part 1</title>
</head>
<body onload="do_game()">
<script type="javascript/text">
var target_index;
var guess_input_text= "none";
var guess_input;
var finished = false;
var guess = 1;
var colors=["blue","yellow","red","green","brown","black"];
colors= colors.sort();
function do_game() {
var random_number = (Math.random() * (colors.length-0)) + 0;
var random_number_integer = Math.floor(random_number);
target_index= random_number_integer;
var target = String(colors[random_number_integer]);
alert("" + target);
while (!finished) {
guess_input_text = prompt("I am thinking of one of these colors: \n\n" +
colors.join(",") + "\n\n What color am I thinking of?");
guess_input = colors.indexOf(guess_input_text);
guess += 1;
finished = check_guess();
}
}
</script>
</body>
</html>
함수를 호출하지 마십시오. –
제쳐두고'var target = String (colors [random_number_integer]);'줄에서 배열의 값이 이미 문자열이기 때문에'String()'을 사용할 필요가 없습니다. – nnnnnn