我正在尝试制作一个对象,其中包括团队得分(如下所示,“this.update”处)。 当我运行程序时,它似乎没有将积分给予团队,并且甚至没有评估双方的目标。
我希望从类似于上面的IF语句或其他解决方案中派生team1Points和team2Points属性,类似于平局每个团队1分,胜利3分,输了0分。
我希望从类似于上面的IF语句或其他解决方案中派生team1Points和team2Points属性,类似于平局每个团队1分,胜利3分,输了0分。
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 = 0
等语句。 - Mark