2016-04-13 5 views
0

私はちょうどHTMLとJavaScriptのコーディングを開始しました。誰か助けてもらえますか?私は複数のサイトを調べて、なぜこのスクリプトが機能していないのかを確認し、このスクリプトが参照する他のすべての機能は完全に動作しています。ここで私は、簡単なオンラインのチームのクイズゲームを動作するために必要なものです: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> 
+0

あなたはどのようなエラーを取得していますか? FORループは正しく見えません。無限ループのように見えます – Erick

+0

エラーはありませんが、8行目の警告に[OK]をクリックした後、[警告(「また、ラウンドがカウントダウンしたことを認識していることを確認してください。 1/15ラウンドは終わりです。 ")]、その後は何も起こりません。それをプログラムに入れた後、エラーを認識しませんでした。 – DerpyCoal

+0

正しい。あなたのループが間違っているためです – Erick

答えて

1

私はあなたが次られた操作を行うためにどのような意味だと思う:私はFORループでやった

<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> 

注意してください。私たちはラウンド変数の周りをループするつもりです。 2ラウンドがある場合は、それが表示されます。

  1. ROUND 1/2

  2. ROUND 2/2

あなたのループが正しくありませんでした。

+0

それは理にかなっています!バンドルありがとう! – DerpyCoal

+0

これで問題が解決した場合は、チェックマークをクリックして最善の回答としてください。ありがとう! – Erick

+0

オリジナルのアイデアを保つには、 'var i = rounds; i> 0である。私は元の質問を正しく理解していれば – Zachariel

0

あなたが頭や体へ<script>タグを追加適切な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>teamgame();</script> 

あなただけ(teamgameを追加することもできます)。関数の閉じ括弧の下に、同じスクリプトタグの中に記述します。

また違ったループ内でアラートをフォーマット:

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

をその後もForループ

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

をquizeme関数を作成:

for (var i=1; i <= rounds; i++) 
関連する問題