The function receives an array with the results of the football championship matches of a team in this format ["3:1", "2:2", "0:1", ...]. The function must calculate and return how many points the team got taking into account: //that its result is the first in each string // a match won adds 3 points, a tie adds 1 point, and losing 0!
I share my code, (it's incomplete, I'm missing the situation in which the team ties and loses) but I don't know how to ask with the if what is the largest number and save it in my earnedpoints variable.
function puntosDelEquipo(array) {
var puntosGanados = 0;
for (var i = 0; i < array.split(":").length; i++) {
if (array[i][0] > array[i][1]) {
puntosGanados = puntosGanados.push(array[i + 3]) {}
}
return puntosGanados;
}
}
Your code is showing the following errors:
The element that your function receives is an array and does not have the split() method - Methods of an array - therefore the for will generate an error:
Within your cycle you are doing
puntosGanados.push
but earnedpoints is a number and does not have that method -Methods of a number- .The solution to this (using if) can be the following: