Project: Sam's Recipe Box Remembers

Sam’s recipe box has come a long way in this course. It saves after every change, loads on every visit, and copes with saves that are missing, damaged, or written by an older copy of the app. Now you’ll put those pieces together into the box Sam actually uses.

In this project, you’ll give every recipe its ingredients, show a count of recipes per category, and make the whole box survive a reload, whatever it finds in storage. This page is the brief you’ll come back to while you build.

What Sam’s Box Should Do

The Add a recipe form, the Filter field with its / shortcut, the Delete dialog, and the status line all stay as they are. The filter text still isn’t saved, because it’s what the page shows, not Sam’s data.

Ingredients under each recipe. Every recipe holds a list of ingredients, each with a name, an amount, and a unit. They show as a nested line under the recipe’s row. A recipe with an empty list shows No ingredients yet there instead, so Sam can tell an empty list from a missing line. The form stays unchanged, so only the starters carry ingredients. A recipe added through the form or migrated from version 1 starts with an empty list.

A count per category. The page shows how many recipes the box holds in each category, worked out from the recipes themselves. The counts follow every add and delete.

A save after every change. The whole box goes into localStorage under one key, "recipe-box", as a version-2 save: JSON text of an object holding a version number and the recipes. Each add and each delete saves the box again, so a reload shows the last change. If the browser refuses a save, the box keeps working and says so on the status line, as in Handle Failed Saves and Lost Data.

A load that never leaves Sam stuck. When the page starts, a version-2 save loads as it is. A version-1 save, such as the one on Sam’s kitchen laptop, is upgraded to version 2.

When there’s no save, or the save can’t be read or has a shape the box doesn’t recognize, the box falls back to three starter recipes and says why on the status line. As in Handle Failed Saves and Lost Data, the box also shows the starters when storage is blocked, with the message This browser is blocking saved data. Showing the starter recipes.

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.