我不明白为什么我的石头,剪刀布游戏中的得分不起作用

用户名

该游戏运行正常,只不过得分不会增加并且我的“裁判员”框未显示基于结果分配给我的文本。

我使用了if else语句来随机分配计算机选择并替换图像,并相应地设置computerChoice变量。我为用户输入使用了if ife语句来分配正确的图像并设置userChoice变量。然后,我使用一组单独的if else语句嵌套来比较computerCoice和userChoice变量,并在裁判框中输出文本,并将广告1指向获胜者得分框,但这部分不起作用。有任何想法吗?

     <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Rock, Paper, Scissors!</title>
    <style>
        .clear {clear: both;}
        .box {width: 160px; height: 150px; float: left; border: 4px solid #000;}
        .wrap {width: 110px; float: left;}
        .wrap input {width: 85px;}
        form {width: 340px; margin: 20px auto 0 auto;}
    </style>

    <script>
    var referee = document.getElementById('ref').value;
    var userScore = document.getElementById('userScore').value;
    var computerScore = document.getElementById('compScore').value;
        userScore = 0;
        computerScore = 0;

        function startGame() {

            var computerChoice = Math.random();

                if (computerChoice >= 0 && computerChoice <= .33) {
                    computerChoice = "rock"
                    document.getElementById("compPic").src = "rock.jpg";

                } else if (computerChoice >= .34 && computerChoice <= .66) {
                    computerChoice = "paper"
                    document.getElementById("compPic").src = "paper.jpg";

                }else if (computerChoice >= .67 && computerChoice <= 1){
                    computerChoice = "scissors"
                    document.getElementById("compPic").src = "scissors.jpg";
                };

            var userChoice = document.getElementById('userChoice').value;

                if (userChoice === "rock" || userChoice === "Rock") {
                    userChoice = "rock";
                    document.getElementById("userPic").src = "rock.jpg";

                } else if (userChoice === "paper" || userChoice === "Paper") {
                    userChoice = "paper";
                    document.getElementById("userPic").src = "paper.jpg";

                } else if (userChoice === "scissors" || userChoice === "Scissors") {
                    userChoice = "scissors";
                    document.getElementById("userPic").src = "scissors.jpg";
                };



                if (userChoice === computerChoice) {
                    referee = "Tie!";
                }else if (userChoice === 'rock') {
                    if (computerChoice === 'paper') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'scissors') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                }else if (userChoice === 'paper') {
                    if (computerChoice === 'scissors') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'rock') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                }else if (userChoice === 'scissors') {
                    if (computerChoice === 'rock') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'paper') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                };

        }
    </script>

</head>
<body>
    <form>

        <div class="box"><img id="userPic" src="rps.jpg"></div>
        <div class="box"><img id="compPic" src="rps.jpg"></div>
        <br class="clear"><br>

        <div class="wrap">
            <label for="userScore">User Score:</label><br>
            <input type="text" name="userScore" id="userScore" value="" readonly>
        </div>
        <div class="wrap">
            <label for="ref">Referee:</label><br>
            <input type="text" name="ref" id="ref" placeholder="Referee's Call..." value="" readonly>
        </div>
        <div class="wrap">
            <label for="compScore">Computer Score:</label><br>
            <input type="text" name="compScore" id="compScore" value="" readonly>
        </div>

        <br class="clear"><br>

        <label for="userChoice">Choose Your Weapon:</label><br>
        <input type="text" name="userChoice" id="userChoice" placeholder="Rock, Paper, or Scissors?">
        <input type="button" value="Battle!" onclick="startGame()">

    </form> 
</body>
</html>
葡萄藤

您必须将用户评分右移至用户评分输入字段。其次,您的得分将在每个游戏上重置。.它不具有可交换性。.我不希望您因可交换性而错过它或它被错过。.define userScore = 0; computerScore = 0; 在函数定义之前。

试试这个

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Rock, Paper, Scissors!</title>
    <style>
        .clear {clear: both;}
        .box {width: 160px; height: 150px; float: left; border: 4px solid #000;}
        .wrap {width: 110px; float: left;}
        .wrap input {width: 85px;}
        form {width: 340px; margin: 20px auto 0 auto;}
    </style>

    <script>
    //var referee = document.getElementById('ref').value;
    //var userScore = document.getElementById('userScore').value;
    //var computerScore = document.getElementById('compScore').value;
        userScore = 0;
        computerScore = 0;

        function startGame() {

            var computerChoice = Math.random();

                if (computerChoice >= 0 && computerChoice <= .33) {
                    computerChoice = "rock"
                    //document.getElementById("compPic").src = "rock.jpg";

                } else if (computerChoice >= .34 && computerChoice <= .66) {
                    computerChoice = "paper"
                    //document.getElementById("compPic").src = "paper.jpg";

                }else if (computerChoice >= .67 && computerChoice <= 1){
                    computerChoice = "scissors"
                    //document.getElementById("compPic").src = "scissors.jpg";
                };

            var userChoice = document.getElementById('userChoice').value;

                if (userChoice === "rock" || userChoice === "Rock") {
                    userChoice = "rock";
                    //document.getElementById("userPic").src = "rock.jpg";

                } else if (userChoice === "paper" || userChoice === "Paper") {
                    userChoice = "paper";
                   // document.getElementById("userPic").src = "paper.jpg";

                } else if (userChoice === "scissors" || userChoice === "Scissors") {
                    userChoice = "scissors";
                   // document.getElementById("userPic").src = "scissors.jpg";
                };



                if (userChoice === computerChoice) {
                    referee = "Tie!";
                }else if (userChoice === 'rock') {
                    if (computerChoice === 'paper') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'scissors') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                }else if (userChoice === 'paper') {
                    if (computerChoice === 'scissors') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'rock') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                }else if (userChoice === 'scissors') {
                    if (computerChoice === 'rock') {
                        referee = 'Computer Wins!';
                        computerScore = ++computerScore;    
                    } else if (computerChoice === 'paper') {
                        referee = 'You Wins!';
                        userScore = ++userScore;
                    };
                };
    document.getElementById('ref').value = referee;
    document.getElementById('userScore').value = userScore;
    document.getElementById('compScore').value =computerScore;
        }
    </script>

</head>
<body>
    <form>

        <div class="box"><img id="userPic" src="rps.jpg"></div>
        <div class="box"><img id="compPic" src="rps.jpg"></div>
        <br class="clear"><br>

        <div class="wrap">
            <label for="userScore">User Score:</label><br>
            <input type="text" name="userScore" id="userScore" value="" readonly>
        </div>
        <div class="wrap">
            <label for="ref">Referee:</label><br>
            <input type="text" name="ref" id="ref" placeholder="Referee's Call..." value="" readonly>
        </div>
        <div class="wrap">
            <label for="compScore">Computer Score:</label><br>
            <input type="text" name="compScore" id="compScore" value="" readonly>
        </div>

        <br class="clear"><br>

        <label for="userChoice">Choose Your Weapon:</label><br>
        <input type="text" name="userChoice" id="userChoice" placeholder="Rock, Paper, or Scissors?">
        <input type="button" value="Battle!" onclick="startGame()">

    </form> 
</body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我不明白为什么for循环不起作用

来自分类Dev

为什么我的剪刀石头布游戏中的循环无法正常进行?

来自分类Dev

石头剪刀布游戏不起作用

来自分类Dev

我不明白为什么我的.find函数不起作用

来自分类Dev

我不明白为什么我的计算不起作用

来自分类Dev

我不明白为什么我的 Athena (Presto) SQL 查询不起作用

来自分类Dev

我不明白为什么我的代码的“再玩”药水不起作用

来自分类Dev

我不明白为什么这个查询不起作用

来自分类Dev

全局语句不起作用,我不明白为什么

来自分类Dev

我不明白为什么这个查询不起作用

来自分类Dev

JQuery、PHP 和 mySQL 帮助。我不明白为什么这不起作用

来自分类Dev

我不明白为什么cordova 链接和Javascript 编码不起作用

来自分类Dev

Java:我不明白为什么这不起作用

来自分类Dev

我不明白为什么这个 Array 不起作用?

来自分类Dev

不明白为什么我的 php 余弦相似度代码不起作用

来自分类Dev

我不明白为什么在我的代码中使用“”会起作用,但是与“”相同的代码却不起作用

来自分类Dev

我不明白为什么这种线程情况不起作用 <线程锁不起作用>

来自分类Dev

为什么我的Java游戏中的if语句不起作用?

来自分类Dev

为什么在康威的生活游戏中,吉尔德变成了追随者?我只是不明白

来自分类Dev

我在哪里检查我的剪刀石头布游戏中的有效输入

来自分类Dev

你能帮我找出这段代码中的错误吗?我似乎不明白为什么它不起作用?

来自分类Dev

我遇到一个奇怪的问题,使用NOT IN对PostgreSQL数据库运行查询,并且不明白为什么它不起作用

来自分类Dev

我不明白为什么带options_from_collection_for_select的f.select的Ruby on Rails代码不起作用

来自分类Dev

Pygame如何在我的游戏中设置碰撞,我不明白

来自分类Dev

如果语句不起作用,则用剪刀石头布剪

来自分类Dev

剪刀石头布程序不起作用(Python)

来自分类Dev

石头剪刀布 window.alert 不起作用

来自分类Dev

C 编程石头剪刀布不起作用

来自分类Dev

不明白为什么数字和代码不起作用

Related 相关文章

  1. 1

    我不明白为什么for循环不起作用

  2. 2

    为什么我的剪刀石头布游戏中的循环无法正常进行?

  3. 3

    石头剪刀布游戏不起作用

  4. 4

    我不明白为什么我的.find函数不起作用

  5. 5

    我不明白为什么我的计算不起作用

  6. 6

    我不明白为什么我的 Athena (Presto) SQL 查询不起作用

  7. 7

    我不明白为什么我的代码的“再玩”药水不起作用

  8. 8

    我不明白为什么这个查询不起作用

  9. 9

    全局语句不起作用,我不明白为什么

  10. 10

    我不明白为什么这个查询不起作用

  11. 11

    JQuery、PHP 和 mySQL 帮助。我不明白为什么这不起作用

  12. 12

    我不明白为什么cordova 链接和Javascript 编码不起作用

  13. 13

    Java:我不明白为什么这不起作用

  14. 14

    我不明白为什么这个 Array 不起作用?

  15. 15

    不明白为什么我的 php 余弦相似度代码不起作用

  16. 16

    我不明白为什么在我的代码中使用“”会起作用,但是与“”相同的代码却不起作用

  17. 17

    我不明白为什么这种线程情况不起作用 <线程锁不起作用>

  18. 18

    为什么我的Java游戏中的if语句不起作用?

  19. 19

    为什么在康威的生活游戏中,吉尔德变成了追随者?我只是不明白

  20. 20

    我在哪里检查我的剪刀石头布游戏中的有效输入

  21. 21

    你能帮我找出这段代码中的错误吗?我似乎不明白为什么它不起作用?

  22. 22

    我遇到一个奇怪的问题,使用NOT IN对PostgreSQL数据库运行查询,并且不明白为什么它不起作用

  23. 23

    我不明白为什么带options_from_collection_for_select的f.select的Ruby on Rails代码不起作用

  24. 24

    Pygame如何在我的游戏中设置碰撞,我不明白

  25. 25

    如果语句不起作用,则用剪刀石头布剪

  26. 26

    剪刀石头布程序不起作用(Python)

  27. 27

    石头剪刀布 window.alert 不起作用

  28. 28

    C 编程石头剪刀布不起作用

  29. 29

    不明白为什么数字和代码不起作用

热门标签

归档