I am trying to make an object that includes the teams points (as shown below where it says "this.update"). When I run the program it does not seem to give the points to the teams and it does not seem to even evaluate both teams' goals.
I want the team1Points and team2Points properties to be derived from an IF statement like the one above or another solution would help, akin to the 1 point to both teams for a draw, 3 points for a win, 0 for a loss.
teamsArray = ["Blue Team", "Red Team"];
function match(team1Name, team2Name, team1Goals, team2Goals) {
this.team1Name = team1Name;
this.team1Goals = team1Goals;
this.team2Name = team2Name;
this.team2Goals = team2Goals;
this.update = function() {
if (team1Goals > team2Goals) {
team1Points = 3;
team2Points = 0;
} else if (team2Goals > team1Goals) {
team2Points = 3;
team1Points = 0;
} else if (team1Goals == team2Goals) {
team1Points = 1;
team2Points = 1;
}
};
this.update();
}
testMatch();
function testMatch() {
var match1 = new match(teamsArray[0], teamsArray[1], 2, 0);
console.log(match1);
}
this.team1Points = 0etc.