html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<!-- Code by Jay used with permission to answer this
question. I massively changed his code.
https://www.sololearn.com/Discuss/859628/?ref=app
-->
<html>
<head>
<title>Teams</title>
<link rel="stylesheet" href="teams.css">
<script src="teams.js"></script>
</head>
<body>
<input type="button" value="Randomize"
onclick="randomize();">
<input type="button" value="New Game"
onclick="newGame();">
<p></p>
<table id="table">
</table>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
/* All table elements should have a black border. */
table, th {
border: 1px solid black;
}
td {
border: 1px solid black;
text-align: center;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Code by Jay used with permission to answer this
// question. I massively changed his code.
// https://www.sololearn.com/Discuss/859628/?ref=app
// Define an class for teams with a name, an array of
// goals for a game, points earned for the games, and
// a unique index. Add the new team to the array of
// teams.
function Team(name) {
this.name = name;
this.goals = [];
this.points = 0;
this.index = window.teams.length;
window.teams.push(this);
}
// Define a method match for the team class. It is
// called with a second object, compares the goals
// in the last game, and rewards 3 points for a win
// to the winner or 1 point to both for a draw.
Team.prototype.match = function(other) {
if (this.goals[this.goals.length-1] >
other.goals[other.goals.length-1]) {
this.points += 3;
} else if (this.goals[this.goals.length-1] <
other.goals[other.goals.length-1]) {
other.points += 3;
} else {
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run