A tiny snack tracker with a problem: some of it is broken, and some of it was never finished. Fixing it will be your job in this unit.
Snack Stash keeps a list of the snacks you're hoarding. You can add a snack with a star rating, mark a snack as eaten, and see your stats at the top of the page. At least, that's what it's supposed to do.
- Fork this repo, then clone your fork (the Unit 13 lessons on CSX walk you through this).
- Open the project folder in VSCode.
- Open
index.htmlin your browser. On a Mac, right-click it in Finder and choose Open With, then your browser. On Windows with WSL, runexplorer.exe .in the integrated terminal, then double-clickindex.htmlin the window that opens. - After every change you make, save the file and refresh the browser to see the result.
- OpenCode should stay in Plan mode for the whole unit. It can explain, locate, and suggest. It should not be allowed to edit.
- You make every code change yourself. If a change is made in any file, you should be the one who made it.
- This README is the source of truth for what to build. OpenCode helps with where and why.
- Before you change any code, be able to explain in plain English what it does now and what your change will do.
| File | Responsibility |
|---|---|
index.html |
The page itself: the header, the add-a-snack controls, the snack list, and the buttons. |
styles.css |
The looks. Nothing in here changes behavior. |
js/stash.js |
The data: the stash array and the functions that change it. |
js/render.js |
The drawing: reads the stash and updates what you see on the page. |
js/app.js |
The wiring: connects buttons to functions and kicks off the first render. |
Every challenge below follows the same seven steps. You walked them once, fully guided, in the CSX lesson for Challenge 1. Keep them nearby:
- Read the challenge's goal below, and restate it in your own words.
- Read the success checkpoint, then watch it fail in the browser.
- Investigate with OpenCode in Plan mode. Locate the code involved, then ask for a line-by-line explanation.
- Explain the problem yourself, in plain English, and run your hypothesis past OpenCode.
- Make the change with your own hands.
- Validate against the success checkpoint, and check that the features around your change still work.
- Write down what was broken (or missing), what you changed, and why it works now. This will be helpful when you need to write a commit message or a pull request description.
If you get stuck, tell OpenCode what you expected and what you saw instead, and ask it where your reasoning went wrong.
Open the app and look at the stats pill at the top. It says 5 snacks are left to enjoy. Now look at the list: two snacks are crossed out because they've already been eaten. Mark another snack as eaten and watch the stats. The "left to enjoy" number never goes down.
Your goal: make the "left to enjoy" count show the number of snacks that have not been eaten.
Success checkpoint: on a fresh page load, the stats read 5 snacks logged, 3 left to enjoy. When you mark a snack eaten, the number drops by one.
There's a "Clear the stash" button at the bottom of the list. Click it. Nothing happens.
Your goal: make the Clear button empty the stash.
Success checkpoint: clicking "Clear the stash" removes every snack from the list, and the stats read 0 snacks logged, 0 left to enjoy.
Both fixes working? Get them onto GitHub. In the VSCode integrated terminal (a second one, if OpenCode is holding the first), run the loop you learned in the last unit:
git statusto see the files you changed.git add .to stage them.git commit -m "..."with your own one-line message saying what changed.git pushto send the commit to your fork. Open your fork on GitHub and confirm your changes are there.
This one is a brand new feature, built the way you built features in the last unit: on a feature branch, finished with a pull request you review yourself.
Your goal: add a "5-star snacks only" button that filters the list. Clicking it shows only the snacks rated 5 stars. Clicking it again brings the whole stash back.
- Before writing any code create a feature branch by running
git switch -c five-star-filter - Build the feature with the same seven steps. A new feature still gets a goal, a checkpoint, an investigation, and an explanation before any code.
- Commit as you go, and push the branch to your fork:
git push -u origin five-star-filter - On GitHub, open a pull request on your fork.
- Read your own diff, then write a short PR summary explaining what changed, why, and how to verify it.
- Merge the pull request, then update it locally on your computer with
git switch mainandgit pull.
Success checkpoint: with the starter data, turning the filter on shows exactly 2 snacks (Sour gummies and Dark chocolate). Turning it off shows all 5, and adding or eating snacks still works afterward.
- All three success checkpoints pass in your browser.
- Your fixes for Challenges 1 and 2 are committed and pushed to your fork.
- You merged the pull request for your Challenge 3 feature into the main branch of your fork.
- You can confidently explain every change you made.
All four boxes checked? Head back to CSX. The final lesson of the unit is waiting for you.