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 Respostas
+ 2
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
+ 5
Bartosz Kurek can you just copy your code in the code playground and attach it here. In my opinion the code is incomplete as the last line is not completed. So we can help it fix for you
11th Nov 2024, 4:41 PM
Aysha
Aysha - avatar
+ 4
Jerry Hobby , the code does not need to be *public*. if we use it as *private*, it can be seen and executed if we open it from inside the post. but it can not be seen in the code area. > making a code *public* makes it additionally visible and accessible in the codec area.
11th Nov 2024, 7:42 PM
Lothar
Lothar - avatar
+ 3
Thank you Lothar. I'm a tiny bit smarter because of you. :)
11th Nov 2024, 9:14 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Bartosz Kurek if it is the same code as the one in your profile codes, then the problem is that you can't use local storage in Sololearn app. It's a restriction in the app for security reasons.
12th Nov 2024, 1:20 AM
Bob_Li
Bob_Li - avatar
+ 1
That code is incomplete. It will be much easier to fix your code if you provide ALL of it in a code bits project. Create a Code Bits project. Put everything there and get it working best you can. Then mark it as PUBLIC. Share that link to us.
11th Nov 2024, 5:07 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
Thanks bro
14th Nov 2024, 3:27 PM
Bartosz Kurek
Bartosz Kurek - avatar
14th Nov 2024, 3:02 PM
Bartosz Kurek
Bartosz Kurek - avatar