<header>
  <h2 class="title">Клас "NotesApp"</h2>
  <p class="description">Реалізує систему управління нотатками з додаванням і видаленням записів.</p>
</header>
<main>
  <div class="result">
    <!-- Форма для додавання нотатки -->
    <form id="note-form">
      <label for="note-input">Введіть нотатку:</label>
      <input type="text" id="note-input" placeholder="Наприклад, купити молоко" required />
      <button type="submit">Додати нотатку</button>
    </form>
    <!-- Список нотаток -->
    <ul id="notes-list" style="margin-top: 15px;"></ul>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

ul {
  list-style: none;
  padding: 0;
}

li {
  padding: 10px;
  margin: 5px 0;
  background-color: #f9f9f9;
  border: 1px solid #ccc;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

li button {
  padding: 5px 10px;
  background-color: #dc3545;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

li button:hover {
  background-color: #c82333;
}
class NotesApp {
  constructor() {
    this.notes = []; // Масив нотаток
  }

  // Додає нову нотатку
  addNote(note) {
    this.notes.push(note);
    this.renderNotes();
  }

  // Видаляє нотатку за індексом
  deleteNote(index) {
    this.notes.splice(index, 1);
    this.renderNotes();
  }

  // Відображає нотатки на сторінці
  renderNotes() {
    const notesList = document.getElementById('notes-list');
    notesList.innerHTML = '';

    this.notes.forEach((note, index) => {
      const noteItem = document.createElement('li');
      noteItem.textContent = note;

      const deleteButton = document.createElement('button');
      deleteButton.textContent = 'Видалити';
      deleteButton.addEventListener('click', () => this.deleteNote(index));

      noteItem.appendChild(deleteButton);
      notesList.appendChild(noteItem);
    });
  }
}

// Ініціалізація програми
const app = new NotesApp();
const form = document.getElementById('note-form');
const input = document.getElementById('note-input');

form.addEventListener('submit', function (event) {
  event.preventDefault(); // Забороняємо перезавантаження сторінки
  const note = input.value.trim();
  if (note) {
    app.addNote(note); // Додаємо нотатку
    input.value = ''; // Очищуємо поле вводу
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.