簡體   English   中英

HTML / JavaScript代碼錯誤

[英]HTML/JavaScript Code Error

我剛剛開始編寫HTML和JavaScript。 有人可以幫忙嗎? 我查看了多個站點,以了解為什么它不起作用,並且此腳本引用的所有其他功能都完全起作用。 這是我需要工作的一個簡單的在線團隊問答游戲:

<html>
<script>
    function teamgame(){
    alert("Hello! First, we need to know how many players are participating.")
    var players=prompt("How many players are there? The maximum is 25!")
    var teams=prompt("How many are on each team? Make sure your number splits evenly!")
    alert("Make sure to number your teams, when their number comes up it is their teams turn! ex. Round 15/15 is group 15's turn!")
    alert("Also, please make sure that you realise that the rounds count down, for example, round 15/15 is the start, round 1/15 is the end.")
    var rounds=(players/teams)
    var initrounds=(players/teams)
    for (; rounds < 0; rounds--){
            alert("ROUND", rounds, "/", initrounds)
            if(players<26) quizme()
            else alert("The maximum amount of players are 25!")
    }
}
</script>
</html>

我認為您的意思是:

<html>
<script>
    function teamgame()
    {
        alert("Hello! First, we need to know how many players are participating.");

        var players=prompt("How many players are there? The maximum is 25!");

        var teams=prompt("How many are on each team? Make sure your number splits evenly!");

        alert("Make sure to number your teams, when their number comes up it is their teams turn! ex. Round 15/15 is group 15's turn!");

        alert("Also, please make sure that you realise that the rounds count down, for example, round 15/15 is the start, round 1/15 is the end.");

        var rounds=(players/teams);

        var initrounds=(players/teams);

        for (var i=1; i <= rounds; i++)
        {
                alert("ROUND", i, "/", rounds);

                if(players<26) quizme();

                else alert("The maximum amount of players are 25!");
        }
}
</script>
</html>

注意我對FOR循環所做的事情。 我們將循環回合變量。 如果有兩回合,它將顯示:

  1. 回合1/2

  2. 回合2/2

您的循環不正確。

首先,您可能需要將其放入正確的HTML中

<!doctype html>
<html lang="en">
<head>
  <title>The HTML5 Herald</title>
  <meta name="description" content="">
  <meta name="author" content=""
</head>
<body>
</body>
</html>

<script>標記添加到頭部或正文中。 但是您還需要調用您的函數。 您將代碼放在函數中,但是沒有任何調用它的代碼。

像這樣調用函數:

<script>teamgame();</script>

您可以只添加teamgame(); 在相同腳本標簽內函數的右括號下方。

還可以在循環內以不同的方式設置警報格式:

alert("ROUND " + i + "/" + rounds);

然后也創建quizeme函數

function quizme() {
    alert("quizme function");
    //Perform whatever needs to be done for the quiz
}

對於循環:

for (var i=1; i <= rounds; i++)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM