The Table

Time for one more project! This checkpoint puts the functions and objects from the last two lessons to work, together with everything you learned before them. As in the previous checkpoints, the instructions say what the program should print, how you write it is up to you, and each exercise also runs your program with other data.

This time, keep one more thing in mind: write the parts of the program as functions. The exercises don't check that, but each step builds on the previous one, and with functions, you'll use what you've already written again instead of copying it.

The project. You're keeping the table of a small football league. Over three exercises, your program will work out each team's points, find the leader and the teams that haven't lost yet, and then update the table after a new match.

The data. The array teams holds one object for each team: its name and how many of its matches it has won, drawn and lost. teams[0].wins is the number of the Lions' wins, 3.

The task. A win is worth 3 points, a draw 1 point and a loss nothing. Print the table: each team's name and points, in the order of the array. For these teams, the program prints:

Lions: 10
Eagles: 8
Sharks: 4
Wolves: 0

The Lions have won 3 matches and drawn 1, so they have 3 × 3 + 1 = 10 points.

A tip: a function that gets one team and returns its points will come in handy in the next exercises too.

Instructions

Print the table.

Start programming for free

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

Or sign up with:

1/3