Malý repozitář pro WTL 3.I 2025/2026
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
982 B

let todoarray = JSON.parse(localStorage.getItem("todos")) || []
function additem() {
let text = document.getElementById("todoitem").value;
//ošetření jestli je text je prázdný
if(text.trim()=="") {return;}
todoarray.push(text);
console.log(todoarray);
savetodos();
renderlist();
document.getElementById("todoitem").value = "";
}
function savetodos() {
console.log(JSON.stringify(todoarray))
localStorage.setItem("todos",JSON.stringify(todoarray))
}
function renderlist(){
document.getElementById("todoList").innerHTML= "";
todoarray.forEach(createList);
}
function createList(value,index){
i = index+1
document.getElementById("todoList")
.innerHTML += '<li class="todolistitem w-100">'+i+". " + value
+'<button class="btn btn-danger my-1 mx-5" onclick="removeitem('
+index+')">Smazat</li>';
}
function removeitem(index){
todoarray.splice(index,1);
savetodos();
renderlist();
}
renderlist();