Javascript - Challenge 1: Data
Code Life
By Pierre Marsaa
The Codédex Report
Welcome to your first final challenge! A trainer's save file arrives as raw JSON text. Turn it into a clean, aligned report — and survive a corrupted file along the way.
This challenge combines JSON, destructuring, array methods, string padding, Set and error handling. Take your time and build it step by step.
Step 1: loadSave(text) parses the JSON text inside a try...catch and returns the resulting object, or null if the text is invalid.
Step 2: printReport(text) loads the save with loadSave. If the result is null, it prints "Corrupted save file" and stops. Otherwise it prints the header "=== Sam's Codédex (5 badges) ===" using the trainer's name and badges.
Step 3: for each team member, print one line: the name padded to 10 characters, then "Lv.X" padded to 6, then "hp/maxHp". Add " FAINTED" at the end when the hp is 0.
Step 4: then print three stats lines:
- "Ready to fight: N/M" — members with hp above 0, out of the team size
- "Average level: X" — computed with reduce
- "Unique moves: N" — the number of different moves across the whole team (use a Set)
Step 5: call printReport(saveFile), then printReport(brokenFile).
Expected output:
Loading editor...
↗️
Loading editor...
↶
↷
💡 Show Solution
Finish