Water counter with a daily goal, max limit, and +/- buttons
Build a small widget that tracks how many glasses of water the user has had today. It counts up and down with two buttons, shows how far the user is from a daily goal, and lets them keep logging past the goal up to a sensible limit.
The starter code includes the goal and the limit:
const DAILY_GOAL = 8;
const MAX_GLASSES = 12;
{count} of 8 glasses, for example 3 of 8 glasses. Past the goal it keeps the same format: 10 of 8 glasses.{DAILY_GOAL - count} to go, for example 5 to go. Once the count reaches the goal, show Goal reached! instead.<button>s, Add glass (+1) and Remove glass (−1).MAX_GLASSES. Remove glass is disabled at 0 and Add glass is disabled at MAX_GLASSES (the disabled attribute, or aria-disabled="true" plus a guard in the handler).aria-live="polite" (or role="status"), so screen readers announce each change.MAX_GLASSES. Base each update on the latest count (in React, setCount((c) => ...)), not on the value captured during the last render.Start 0 of 8 glasses 8 to go [Remove glass] disabled
Add glass x3 3 of 8 glasses 5 to go
Remove glass 2 of 8 glasses 6 to go
Add glass x6 8 of 8 glasses Goal reached!
Add glass x4 12 of 8 glasses Goal reached! [Add glass] disabled
2 quick clicks at 11 12 of 8 glasses (not 13)
Goal reached!, not 0 to go.to go text.The tests click your buttons and read the text on the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
disabled or aria-disabled="true".N of 8 glasses, N to go and Goal reached! appear as described, and the count is inside an aria-live="polite" or role="status" element.click events on Add glass inside a single ReactDOM.flushSync call.Capitalization and extra spacing don’t matter.