Javascript石头、布、剪刀类游戏的问题

Javascript石头、布、剪刀类游戏的问题,javascript,arrays,function,variables,Javascript,Arrays,Function,Variables,我遇到了一个选择根本没有更新的问题。我已经列出了每次选择后最后的结果和当前的分数应该显示在哪里。分数运行良好,但选择根本没有更新。谢谢 <html> <head> <title> Dynamic Web </title> </head> <body> <div class="container"> <a class="contents content1"> <h1>Squ

我遇到了一个选择根本没有更新的问题。我已经列出了每次选择后最后的结果和当前的分数应该显示在哪里。分数运行良好,但选择根本没有更新。谢谢

<html>
<head>
<title> Dynamic Web </title>
</head>

<body>


<div class="container">

<a class="contents content1">

    <h1>Squirtle, Charmander, Bulbasuar</h1>

    <div class="p-r-s">

        <div class="one_three">

            <h3>Take your pick</h3>

            <ul class="choices">
                <li>
                    <a onclick="compare('Squirtle', computerChoice)">
                        <img src="assets/img/paper.png" width="50px" />
                    </a>
                </li>

                <li>
                    <a onclick="compare('Charmander', computerChoice)">
                        <img src="assets/img/rock.png" width="50px" />
                    </a>
                </li>

                <li>
                    <a onclick="compare('Bulbasuar', computerChoice)">
                        <img src="assets/img/scissors.png" width="50px" />
                    </a>
                </li>
            </ul>

        </div> <!-- one_three -->

        <div>

                <h3>Scores</h3>

                <div class="scores">

                    <div class="score-box">

                        <div id="playerScore"></div><!-- .computerScore -->

                        <span>Player</span>

                    </div><!-- score-box -->

                    <div class="score-box">

                        <div id="computerScore"></div><!-- .computerScore -->

                        <span>Computer</span>

                    </div><!-- score-box -->

            </div><!-- .scores -->

        </div> <!-- two_three -->


        <div>

            <h3>Choices</h3>

            <ul class="decider">

                <li>

                        <span>Player:</span>
                        <span id="playerChoice">Pick one to get started!</span><!-- .playerChoice -->

                </li>

                <li>

                        <span>Computer:</span>
                        <span id="computerChoice">You first!</span><!-- .computerChoice -->

                </li>


            </ul>

        </div>

</div> <!-- .row -->

动态网络
斯奎特尔、查曼德、布尔巴苏尔
你挑吧
分数 玩家 电脑类 选择
  • 玩家: 选择一个开始!
  • 计算机: 你先来!

Javascript

<script type="text/javascript" >

var computerScore = 0
var playerScore = 0

// INSERT SCORES
var playerScoreBox = document.getElementById('playerScore');
var computerScoreBox = document.getElementById('computerScore');

playerScoreBox.innerHTML = computerScore;
computerScoreBox.innerHTML = playerScore;

var playerChoice = document.getElementById('playerChoice');
var computerChoice = document.getElementById('computerChoice')


function compare(choice1, choice2) {

    choice2 = Math.random();
    if (choice2 < 0.34) {
        choice2 = "Charmander";
    } else if(choice2 <= 0.67) {
        choice2 = "Squirtle";
    } else {
        choice2 = "Bulbasuar";
    }

    playerChoice = choice1;
    computerChoice = choice2;


    if (choice1 == choice2) {
        return false;
    }
    if (choice1 == "Charmander") {
        if (choice2 == "Bulbasuar") {

            playerScore++;         
        }
        else {
            computerScore++;
        }
        return updateScores();
    }
    if (choice1 == "Squirtle") {    
        if (choice2 == "Charmander") {
            playerScore++;
        }
        else {
            computerScore++;
        }
        return updateScores();
    }
    if (choice1 == "Bulbasuar") {

        if (choice2 == "Charmander") {
            computerScore++;
        }
        else {
            playerScore++;
        }
        return updateScores();
    }
}

function updateScores() {
    playerScoreBox.innerHTML = playerScore;
    computerScoreBox.innerHTML = computerScore;
}

</script>

var计算机分数=0
var playerScore=0
//插入分数
var playerScoreBox=document.getElementById('playerScore');
var computerScoreBox=document.getElementById('computerScore');
playerCoreBox.innerHTML=计算机分数;
computerScoreBox.innerHTML=playerScore;
var playerChoice=document.getElementById('playerChoice');
var computerChoice=document.getElementById('computerChoice')
功能比较(选项1、选项2){
choice2=Math.random();
如果(选择2<0.34){
choice2=“Charmander”;

}else if(choice2
playerChoice=choice1;
应该是
playerChoice.value=choice1;
playerChoice.innerHTML=choice1;
,这取决于它是否是一个输入。与
computerChoice
相同