

Habit Tracker
A habit app stores one boolean per day: true when you did the habit. Write trackHabit(days) that returns an object with three numbers:
total: how many days were tickedlongest: the longest run of ticked days in a rowcurrent: the run that is still going at the end of the list
Build it step by step
- Loop over
dayswithfor...of. - On a ticked day, add one to
totaland one tocurrent. - After each ticked day, update
longestwithMath.max(longest, current). - On a missed day, reset
currentto 0.
Examples
trackHabit([true, true, false, true, true, true, false])
→ { total: 5, longest: 3, current: 0 }
trackHabit([false, true, true])
→ { total: 2, longest: 2, current: 2 }
project.js
JAVASCRIPT
Saved as you type
Tests
0 of 4 passing- •mixed weektrackHabit([true, true, false, true, true, true, false])expected { total: 5, longest: 3, current: 0 }
- •still goingtrackHabit([false, true, true])expected { total: 2, longest: 2, current: 2 }
- •no daystrackHabit([])expected { total: 0, longest: 0, current: 0 }
- •every daytrackHabit([true, true, true, true])expected { total: 4, longest: 4, current: 4 }
On the line
+200 XP
Pass all 4 tests to claim it.
