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:
- Load
runs.json. If the file itself is broken, stop with an error that names the file and keeps the originalSyntaxErroras its cause. - Check every run record and report each bad one with a line that names the run and the problem.
- Skip the bad runs, keep the rest, and print one line for each run that was kept.
- 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.jsholdscheckRun(), which throws aTypeError, aRangeError, or a plainErrorfor a bad record. Copy yours from the editor in Exercise: Validate Each Run Record.load.jsholdsloadRuns(path), which reads and parses the file and wraps aSyntaxErrorwith{ cause: error }likeloadSeason()did. It also holdsimportRuns(runs), the import loop from the video, with its smalltryaround the check and the push.report.jsholdsformatRun()andprintSeason(), with the loop bound fixed toi < runs.length.totals.jsholdstotalsByRunner(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.jsis 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.