Project: The Elm Street Toy Library

Over this course, you’ve built each part of the Elm Street toy library’s tracker on its own. You made a family of toys, a lending desk assembled from parts, errors with names, and helpers that turn typed text into numbers. Now a family has donated a garage full of board games, puzzles, and ride-on toys, and the volunteers want one tracker that handles all of them.

This time, there’s no walkthrough. You get the brief, the behavior the volunteers expect, and a script that checks your build. You decide the classes, the parts, and the files yourself, using the two tests you’ve practiced throughout the course. Start with what the volunteers need the tracker to do.

Read the Brief

The volunteers lend three kinds of items, and each kind has a rule the others don’t. The tracker has to know those rules, lend items safely, and read what volunteers type at the terminal. Everything below is the behavior the checks and the next two exercises look for. How you arrange the code behind it is up to you, and you can reuse anything you wrote in the lessons.

The Items

Every item has an .id, a .name, a minimum age, and a .borrower that starts as null. Write an Item base class that all three kinds extend. Each kind adds its own data after the three shared arguments:

Kind Made with .describe() returns
BoardGame new BoardGame("G01", "Ludo", 4, 2, 4) "G01: Ludo (ages 4+), 2-4 players"
Puzzle new Puzzle("P01", "Map jigsaw", 8, 300) "P01: Map jigsaw (ages 8+), 300 pieces"
RideOn new RideOn("R01", "Balance bike", 3, 6) "R01: Balance bike (ages 3+), up to age 6"

A board game’s extra arguments are its minimum and maximum player counts, a puzzle’s is its piece count, and a ride-on’s is its maximum age. Every item also needs these two methods:

  • .isSuitableFor(age) returns true when a child of that age may borrow the item. For most items, that means the age is at least the minimum. A ride-on also has a maximum age, because an 11-year-old would break a balance bike made for a 6-year-old.
  • .label() returns "Shelf label: " followed by the item’s description. Write it once, in Item, so every kind’s label shows that kind’s own description.

A puzzle also counts its missing pieces. The missing-piece count starts at zero, and .recordMissing(count) adds to it. Once pieces are missing, .describe() appends that count, as in "P01: Map jigsaw (ages 8+), 300 pieces, 2 missing".

The Lending Desk

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.