We all reach for a date library the moment a calendar shows up in a feature request. But underneath every grid is plain JavaScript โ counting days, offsetting weekdays, and rolling years over. This challenge drops the library and puts you in charge.
๐งฉ Overview
The calendar components are already provided, so your job is the logic: render the correct days, highlight today, navigate between months, and handle leap years with plain JavaScript date math.
๐ https://www.reactchallenges.com/challenges/calendar
โ Requirements
โข Render the app title "Calendar" and the weekday header (Mon through Sun).
โข Show the current month and year in the header (e.g. August 2026).
โข Render the correct number of days for the selected month (28, 29, 30, or 31).
โข Place the 1st day of the month in the correct weekday column.
โข Fill empty cells with days from the previous and next month so the grid always completes full weeks, dimming those days visually.
โข Navigate to the previous and next month.
โข Highlight the current day (today) in the grid.
โข Change the year correctly when navigating past December or before January.
โข Handle leap years correctly (February has 29 days in a leap year, 28 otherwise).
๐ก Notes
โข new Date(year, month + 1, 0).getDate() returns the number of days in a month โ leap years included.
โข The week starts on Monday, so the leading offset for the 1st day is (getDay() + 6) % 7.
โข new Date(year, month + offset, 1) rolls the year over automatically when navigating past December or January.
๐งช Tests
- renders the app title
- renders the seven weekday labels
- shows the current month and year in the header
- renders the correct number of days for the current month
- places the 1st day on the correct weekday
- fills the grid with days from the previous and next month
- navigates to the next month
- navigates to the previous month
- changes the year when navigating past December
- changes the year when navigating before January
- highlights today's date
- does not highlight any day when viewing another month
- renders 28 days for February in a non-leap year
- renders 29 days for February in a leap year
- renders 30 days for a 30-day month
- uses five weeks when the month fits in five
You'll walk away confident counting days, offsetting weekdays, and handling leap years without a single dependency. 16 tests will tell you exactly where your grid breaks.
Top comments (0)