AnnaCherem / AnnaCheremashentseva

0 stars 0 forks source link

HW27 #16

Open MarynaBasieva opened 5 months ago

MarynaBasieva commented 5 months ago

У вашому коді були помічені деякі помилки та можливі покращення.

const ul = document.querySelector('ul'); const input = document.getElementById('item'); let itemsArray = localStorage.getItem('items') ? JSON.parse(localStorage.getItem('items')) : [];

if (!itemsArray) { itemsArray = []; }

function addTask(text) { let newTask = document.createElement('li'); newTask.textContent = text; ul.appendChild(newTask); }

function add() { const newItemValue = input.value.trim(); if (newItemValue !== "") { itemsArray.push(newItemValue); localStorage.setItem('items', JSON.stringify(itemsArray)); addTask(newItemValue); input.value = ""; } }

function del() { localStorage.removeItem('items'); itemsArray = []; ul.innerHTML = ""; }

itemsArray.forEach(task => addTask(task));

AnnaCherem commented 5 months ago

Виправила дякую

MarynaBasieva commented 5 months ago

все добре