Project: The Hilltop Season Log

Ruth’s season log has picked up every tool from this course one piece at a time. checkRun() throws an error that names a bad run, the import loop catches it and skips the run, and you used a debugging card to find Priya’s missing 10 km when nothing threw at all. Now Ruth has the rest of May to add, and she wants one program that does all of it.

In this project, you’ll create that program. You’ll read what Ruth needs it to print, see which file does each job, and build it in steps that the next exercises check as you go. Every piece is one you’ve met already, so the work is in fitting them together.

Read Ruth’s Brief

A brief says what a program must do before anyone decides how. Ruth’s is short. When she runs node main.js in her season-log folder, the season log should do four things:

  1. Load runs.json. If the file itself is broken, stop with an error that names the file and keeps the original SyntaxError as its cause.
  2. Check every run record and report each bad one with a line that names the run and the problem.
  3. Skip the bad runs, keep the rest, and print one line for each run that was kept.
  4. Print each member’s season: how many runs, how many kilometers, and how many minutes.

The second and third points matter most to Ruth. In her first version, one bad record stopped the whole import, and she had to fix the file one run at a time. This time, she wants a single run of the program to list every problem in the file and still print the good runs.

Each job stays in the file you assigned it to earlier in this course:

  • check.js holds checkRun(), which throws a TypeError, a RangeError, or a plain Error for a bad record. Copy yours from the editor in Exercise: Validate Each Run Record.
  • load.js holds loadRuns(path), which reads and parses the file and wraps a SyntaxError with { cause: error } like loadSeason() did. It also holds importRuns(runs), the import loop from the video, with its small try around the check and the push.
  • report.js holds formatRun() and printSeason(), with the loop bound fixed to i < runs.length.
  • totals.js holds totalsByRunner(runs), which groups the runs by name and gives each runner { runs, km, minutes }. Ruth has written a new version, and you’ll get it in the second step.
  • main.js is the thin entry point that loads, imports, and prints.

The scratch files from the lessons, such as halve.js, look.js, new-runs.json, and the try- scripts, were tryouts. main.js takes over their jobs, so you can delete them. season.js and club.js can go too once their code has moved: the wrap from loadSeason() into loadRuns(), and totalsByRunner() into totals.js. package.json stays as it is.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.