I'm having trouble displaying the value of 'true' within my objects and keep encountering an error message.
Uncaught TypeError: Cannot set property 'toDoIsRemoved' of undefined
at removeTask (main.js:85)
at HTMLButtonElement.<anonymous> (main.js:56)
The error message points to an issue with line 56:
deleteButton.addEventListener('click', ()=>{removeTask(allTheToDos[i])});
Here is the entire function:
function generateHtml (){
// Creating an Ul for my items
let section = document.getElementById('mySection');
let myUl = document.createElement('ul');
myUl.className = 'listContainer';
section.appendChild(myUl);
// Creating the loop for my premade todo objects
for(i=0; i<allTheToDos.length; i++){
// Create a div wrapper for my li
let myListWrapperItemContainer = document.createElement('div');
myListWrapperItemContainer.className = 'listItemsWrapper';
// Creating Checked button
let checkedIcon = document.createElement('label');
checkedIcon.className = 'checkedIcon listItemsIcon';
checkedIcon.innerHTML = '<i class="fas fa-check"></i>';
//Creating li
let myLi = document.createElement('li');
myLi.classList = 'listItem lineTrough';
myLi.id= 'listItem';
// Creating delete button
let deleteButton = document.createElement('button');
deleteButton.id ='deleteButton';
deleteButton.className = 'trashCan listItemsIcon';
deleteButton.innerHTML = '<i class="fas fa-trash-alt"></i>';
// OnClick
deleteButton.addEventListener('click', ()=>{removeTask(allTheToDos[i])});
// Adding everything to my html
myListWrapperItemContainer.appendChild(checkedIcon);
myListWrapperItemContainer.appendChild(myLi);
myListWrapperItemContainer.appendChild(deleteButton);
myLi.innerHTML = allTheToDos[i].toDoItem;
myUl.appendChild(myListWrapperItemContainer);
}
}
and:
function removeTask (done){
done.toDoIsRemoved = true;
console.log(allTheToDos);
}
I am looking to be able to click on any button associated with my todos to change the value from false to true.