Reputation: 59
I have just started coding HTML and JavaScript. Can somebody please help? I looked on multiple sites to see why this wasn't working, and all of the other functions that this script refers to are completely working. Here is what I need to work, a simple online team quiz game:
<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>
Upvotes: -3
Views: 55
Reputation: 519
To start you might want to put it in proper HTML
<!doctype html>
<html lang="en">
<head>
<title>The HTML5 Herald</title>
<meta name="description" content="">
<meta name="author" content=""
</head>
<body>
</body>
</html>
Add the <script>
tags into the head or the body. But you also need to call your function. You put the code in the function but there is nothing calling it to be used.
Call the function like this:
<script>teamgame();</script>
You could just add teamgame(); underneath the closing bracket of your function inside the same script tags.
Also format your alert inside the loop differently:
alert("ROUND " + i + "/" + rounds);
Then create the quizeme function also
function quizme() {
alert("quizme function");
//Perform whatever needs to be done for the quiz
}
For loop:
for (var i=1; i <= rounds; i++)
Upvotes: 0
Reputation: 833
I think what you meant to do was the following:
<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>
Notice what I did with the FOR loop. We are going to loop around rounds variable. If there are 2 rounds, then it will display:
ROUND 1/2
ROUND 2/2
Your loop was incorrect.
Upvotes: 1