私は、ロック、ペーパー、ハサミのゲームをjavascriptで構築しようとしています。ここ は私のコードです:はじめにJavascript - syntax
<script type="text/javascript">
var options = ["r", "p", "s"];
document.onkeyup = function(event) {
console.log("event=", event);
var userGuess = String.fromCharCode(event.which).toLowerCase();
console.log(userGuess);
var computerGuess = options[Math.floor(Math.random() * options.length)];
console.log(computerGuess);
if ((userGuess === "r") && (computerGuess === "p")) {
alert("Paper smothers rock - You lose.");
} else
if ((userGuess === "r") && (computerGuess === "s")) {
alert("Rock smashes scissors - You win!")
} else
if ((userGuess === "p") && (computerGuess === "s")) {
alert("Scissors cuts paper to pieces - You lose.");
} else if ((userGuess === "p") && (computerGuess === "r")) {
alert("Paper smothers rock - You win");
} else if ((userGuess === "s") && (computerGuess === "r")) {
alert("Rock smashes scissors - You lose.");
} else if ((userGuess === "s") && (computerGuess === "p")) {
alert("Scissors cuts paper to pieces - You win!")
} else if (userGuess === computerGuess) {
alert("You tie!");
}
</script>
コンソールで、私はこのエラーを得続けるとき:キャッチされないでSyntaxError:入力 の予期しない終わり、私はそれは恥ずかしいですので、多くのことを試してみました。もう一度、私の完全な正義を許してください。すべてのヘルプは、あなたのonkeyupの関数に閉じ括弧が欠落しているように見えるappreciated.r
あなたは 'onkeyup'機能を閉鎖していないように私に見えます。 '};をファイルの最後に追加します。 –
もっと具体的には、 ' 'の直前の行に'}; 'を追加してください。 –
ありがとうございます。非常に多くの角かっこと括弧と半分lol –