A New Match

A new match has just been played, and it's in a new constant, match: the names of the home team and the away team, and how many goals each of them scored. The Eagles played at home and beat the Lions 2:1.

Below everything the program prints so far, print the result of the match. Then update the table: the winner gets one more win and the loser one more loss, and when both teams scored the same number of goals, each of them gets one more draw. Finally, print the table, the leader and the unbeaten teams again, as they are after the match:

Leader: Lions
Unbeaten: ["Lions", "Eagles"]
Eagles 2:1 Lions
Lions: 10
Eagles: 11
Sharks: 4
Wolves: 0
Leader: Eagles
Unbeaten: ["Eagles"]

The win has taken the Eagles to the top. The exercise also tries a draw and a win of the away team, so make sure that every result updates the table correctly.

A tip: the match gives you only the names of the teams. A function that gets a name, goes through teams and returns the team with that name gives you the object whose properties you need to change.

That's the whole project. Your program keeps a league table: it stores the teams as objects, works out the points, the leader and the unbeaten teams with functions, and updates the objects after a match. In the next lesson, your code will run on a web page, where it changes what the page shows and reacts to clicks. A table like this one could then be shown on a page and update itself after every match.

Instructions

Below everything the program prints so far, print the result of the match.

Update the teams after the match, and print the table, the leader and the unbeaten teams again.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/3