Project: Sam's Recipe Box

In Exercise: Confirm Clearing the Week, the meal planner learned to ask before it clears anything, say what it did, and put the focus somewhere useful. Sam’s family recipes, though, are still on index cards in a shoebox, and Sam can never find the one for banana bread.

In this project, you’ll build Sam’s recipe box: a form that adds recipes and refuses bad ones, a filter you reach with one key, and a Delete button that asks first. You’ve met every piece on the shopping list. Now you’ll put them together from a brief, testing each step with the keyboard alone.

Read Sam’s Brief

Sam wants one page that holds every family recipe, where anyone can add a recipe, find one by typing part of its name, and delete one without fear of losing the wrong card. Kofi plans meals with the keyboard alone, and Mei listens with a screen reader, so the page has to work for both of them.

Each recipe is a record with six properties:

  • id, from crypto.randomUUID(), so two recipes never share one
  • name, such as Banana bread, without spaces at either end
  • servings, a number from 1 to 20
  • minutes, a number of at least 1, for how long the recipe takes
  • category, one of soup, main, baking, or dessert
  • vegetarian, true or false

Banana bread’s record looks like this, with its ID shortened:

Language: JavaScript
{
  id: "8f1c2a4e-...",
  name: "Banana bread",
  servings: 8,
  minutes: 70,
  category: "baking",
  vegetarian: true,
}

The box starts with five recipes Sam copied from the cards: Grandma Ines’s lentil soup, Sunday roast chicken, Banana bread, Weeknight fried rice, and Lemon drizzle cake.

The list shows one row per recipe, such as Banana bread (serves 8, 70 min), baking, vegetarian, followed by a Delete Banana bread button. A recipe that isn’t vegetarian has no , vegetarian at the end: Weeknight fried rice (serves 2, 20 min), main.

The recipes live in one array, recipes, as Priya’s guests and Sam’s shopping items did. Every change goes to the array first, and then render() redraws the list from it. The page never keeps a second copy of the data, so what Sam sees always matches the array.

Know What Sam Expects

The exercises’ tests check these rules, so read them now and come back to them as you build:

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.