Changed around line 1
+ // Load saved notes from localStorage
+ const notesContainer = document.getElementById('notes-container');
+ const noteInput = document.getElementById('note-text');
+ const saveBtn = document.getElementById('save-btn');
+ const clearBtn = document.getElementById('clear-btn');
+
+ let notes = JSON.parse(localStorage.getItem('notes')) || [];
+
+ function renderNotes() {
+ notesContainer.innerHTML = '';
+ notes.forEach((note, index) => {
+ const noteItem = document.createElement('li');
+ noteItem.className = 'note-item';
+ noteItem.innerHTML = `
+ ${note}
+ ✕
+ `;
+ notesContainer.appendChild(noteItem);
+ });
+ }
+
+ function saveNote() {
+ const noteText = noteInput.value.trim();
+ if (noteText) {
+ notes.push(noteText);
+ localStorage.setItem('notes', JSON.stringify(notes));
+ noteInput.value = '';
+ renderNotes();
+ }
+ }
+
+ function deleteNote(index) {
+ notes.splice(index, 1);
+ localStorage.setItem('notes', JSON.stringify(notes));
+ renderNotes();
+ }
+
+ function clearNotes() {
+ notes = [];
+ localStorage.removeItem('notes');
+ renderNotes();
+ }
+
+ // Event listeners
+ saveBtn.addEventListener('click', saveNote);
+ clearBtn.addEventListener('click', clearNotes);
+
+ // Initial render
+ renderNotes();