Lay Out a Month Calendar

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code
  • Pro

The Calendar component gets year and month props, with month from 1 for January to 12 for December, and shows that month. A heading names it in English with the year, like "February 2026". Below it, a real table: a thead with one header row of "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" and "Sun" (weeks start on Monday), then a tbody with one row per week, each with exactly 7 cells. Every day of the month has its own cell holding just its number, under the right weekday; cells before the 1st and after the last day are empty. Use only as many rows as the month needs, and remember leap years. "Previous month" and "Next month" buttons change the month shown, rolling over the year, so December 2025 is followed by January 2026. Work the weekdays out with Date.UTC and getUTCDay (or plain arithmetic), never local time, so the calendar is right in every time zone.

Your code must pass

  • Names the month and year in a heading, like "February 2026"
  • Has a header row of weekdays, starting on Monday
  • Puts the 1st under the right weekday
  • Has one row per week, with every day once
  • Previous month and Next month change the month, across years