ボタンをクリックすると、compOutputボックスまたはwinOutputボックスに出力したいものが表示されません。私はこのプロジェクトのほとんどをcodecademyの例から取り出し、それをWebページに実装しようとしました。私はまた、コードが実行されたら、すべてのフィールドをクリアしたいので、誰かがそれのためのコードを私にも与えることができますか?それは私が問題を抱えているだけの出力です。シンプルなJavaScriptのはさみのゲーム
var userChoice = document.getElementById('userInput').value;
var computerChoice = Math.random();
\t if (computerChoice < 0.34) {
\t \t computerChoice = "rock";
\t } else if (computerChoice < 0.67) {
\t \t computerChoice = "paper";
\t } else {
\t \t computerChoice = "scissors";
\t }
function compare(choice1, choice2) {
\t document.getElementById('compOutput').value = computerChoice;
\t //tie
\t if (choice1 === choice2) {
\t \t document.getElementById('winOutput').value = "The result is a tie!";
\t }
\t //choice1 rock & choice2 scissors
\t else if (choice1 === "rock") {
\t \t if (choice2 === "scissors") {
\t \t \t document.getElementById('winOutput').value = "rock wins";
\t \t }
\t }
\t //choice1 paper & choice2 rock
\t else if (choice1 === "paper") {
\t \t if (choice2 === "rock") {
\t \t \t document.getElementById('winOutput').value = "paper wins";
\t \t } else {
\t \t \t document.getElementById('winOutput').value = "scissors wins";
\t \t }
\t }
\t //choice1 scissors
\t else if (choice1 === "scissors") {
\t \t if (choice2 === "rock") {
\t \t \t document.getElementById('winOutput').value = "rock wins";
\t \t } else if (choice2 === "paper") {
\t \t \t document.getElementById('winOutput').value = "scissors wins";
\t \t }
\t }
}
<body>
\t <form>
\t \t <table align="center">
\t \t \t <tr>
\t \t \t \t <td>
\t \t \t \t \t <h5>Rock, Paper, Scissors?</h5>
\t \t \t \t </td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td><input type="text" id="userInput"></td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td>
\t \t \t \t \t <h5>Computer Choice</h5>
\t \t \t \t </td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td><input type="text" id="compOutput"></td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td>
\t \t \t \t \t <h5>Winner</h5>
\t \t \t \t </td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td><input type="text" id="winOutput"></td>
\t \t \t </tr>
\t \t \t <tr>
\t \t \t \t <td><input type="button" id="generate" value="Click Here" onclick="compare(userChoice, computerhoice)"></td>
\t \t \t </tr>
\t \t </table>
\t </form>
</body>
私は、ボタンのクリックを検出し、あなたのコードを実行するために、JavaScriptでリスナーを使用してお勧めしたいです。 –