0

Fix my code

Can someone fix my code (just create new code with my code) document.addEventListener("DOMContentLoaded", function() { const taskForm = document.getElementById("task-form"); const taskInput = document.getElementById("task-input"); const taskList = document.getElementById("task-list"); loadTasks(); taskForm.addEvent("submit", function(event) { event.preventDefault(); addTask(taskInput.value); taskInput.value = "" }); function addTask(taskText) { const taskItem = document.createElement("li"); taskItem.className = "task-item"; taskItem.textContent = taskText; const deleteBtn = document.createElement("button"); deleteBtn.textContent = "Delete"; deleteBtn.addEventListener("click", () => { taskList.removeChild(taskItem); saveTasks(); }); } function saveTasks() { const tasks = []; document.querySelectorAll(".task-item").forEach(item =

11th Nov 2024, 4:01 PM
Bartosz Kurek
Bartosz Kurek - avatar
8 ответов
+ 1
Bartosz Kurek there are few errors in your code. 1) you used addEvent instead of addEventListener. 2) you passed tasks as an array. Instead it expects string for each task. 3) you forgot to append the taskItem to taskList. You need to add items to the list so it will be visible on the page.
14th Nov 2024, 3:25 PM
Aysha
Aysha - avatar