Changed around line 1
+ const monthNames = [
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"
+ ];
+
+ const calendarDays = document.getElementById('calendar-days');
+ const currentMonthElement = document.getElementById('current-month');
+ const prevMonthButton = document.getElementById('prev-month');
+ const nextMonthButton = document.getElementById('next-month');
+
+ let currentDate = new Date();
+
+ function renderCalendar() {
+ const year = currentDate.getFullYear();
+ const month = currentDate.getMonth();
+
+ currentMonthElement.textContent = `${monthNamesonth]} ${year}`;
+
+ const firstDay = new Date(year, month, 1);
+ const lastDay = new Date(year, month + 1, 0);
+ const daysInMonth = lastDay.getDate();
+ const startDay = firstDay.getDay();
+
+ calendarDays.innerHTML = '';
+
+ for (let i = 0; i < startDay; i++) {
+ const emptyDay = document.createElement('div');
+ emptyDay.classList.add('empty');
+ calendarDays.appendChild(emptyDay);
+ }
+
+ for (let day = 1; day <= daysInMonth; day++) {
+ const dayElement = document.createElement('div');
+ dayElement.textContent = day;
+ calendarDays.appendChild(dayElement);
+ }
+ }
+
+ prevMonthButton.addEventListener('click', () => {
+ currentDate.setMonth(currentDate.getMonth() - 1);
+ renderCalendar();
+ });
+
+ nextMonthButton.addEventListener('click', () => {
+ currentDate.setMonth(currentDate.getMonth() + 1);
+ renderCalendar();
+ });
+
+ renderCalendar();