function playGame(userChoice) { var choices = ["グー", "チョキ", "パー"]; var computerChoice = choices[Math.floor(Math.random() * 3)]; var result = Winner(userChoice, computerChoice); displayResult(userChoice, computerChoice, result); } function Winner(userChoice, computerChoice) { if (userChoice === computerChoice) { return "引き分け!"; } if ( (userChoice === "グー" && computerChoice === "チョキ") || (userChoice === "パー" && computerChoice === "グー") || (userChoice === "チョキ" && computerChoice === "パー") ) { return "勝ちました!"; } else { return "負けました!"; } } function displayResult(userChoice, computerChoice, result) { var resultElement = document.getElementById("result"); resultElement.innerHTML = ` <p>あなたの選択: ${userChoice}</p> <p>コンピュータの選択: ${computerChoice}</p> <p>${result}</p> `; }