I'm a beginner building a todo list app in vanilla JS. Im trying to create function that filters through the todo items and displays the items the are either completed , in-completed or All task but im running into the error
task.style is undefined"
const filterTask = document.querySelector('.filter-options'); //select tag in HTML which allows user to select whether they want to display the completed or in-completed task
const todoUl = document.querySelector('.todo-ul'); //the ul under which the tasks become childNodes
filterTask.addEventListener('click', filterTodo)
function filterTodo(e) {
const tasks = todoUl.childNodes;
tasks.forEach((task) => {
switch (e.target.value) {
case "all-task":
task.style.display = "flex";
break;
case "completed-task":
if (task.classList.contains('completed-task')) {
task.style.display = "flex";
} else {
task.style.display = "none";
}
}
})
<select class="filter-options">
<option value="all-task">All Task</option>
<option value="completed-task">Completed Task</option>
<option value="uncompleted-task">Uncompleted Task</option>
</select>