Close the earlier lessons and build this from the brief.
The brief
A study timer that counts minutes you log with buttons. It isn't a real clock yet; that comes on Day 6.
- Show 0 of 60 minutes. The 60 is a constant named
GOAL. - Buttons +5 and +15 add minutes.
- Reset sets the minutes back to 0, and is disabled while the minutes are already 0.
- Once the minutes reach the goal or more, show Goal reached! in bold.
- A Show tips button shows a list of two study tips, and its text changes to Hide tips while they're showing.
Acceptance checks:
- Four clicks on +15 show 60 of 60 minutes and Goal reached!.
- Reset brings back 0 of 60 minutes and removes the message.
- No errors or warnings in the console.
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Hint 1: how many pieces of state?
Two: the minutes, and whether the tips are showing. The goal message isn't state, because it follows from the minutes.
Hint 2: the parts you've seen
Disabling is disabled={...} on the button. The tips use &&. The toggle
button's text uses a ternary.
Show one solution
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Check yourself
- Why doesn't changing an ordinary
letvariable update the page? - What's the difference between
onClick={save}andonClick={save()}? - When should you pass
setCounta function instead of a value?
Completion is saved in this browser only. It does not measure mastery.