I’m trying to add the done
task function to my to do list app, everyting seems fine but when I click on check button, it doesnt add the done
class to li
tag
I’m trying to add the done
task function to my to do list app, everyting seems fine but when I click on check button, it doesnt add the done
class to li
tag
3
Answers
There is no code sample in your question but you can watch the scenario like this:
Finally: it could be more easier to handle those action in a frontend library like react. If you provide code samples there could be more specific help.
It’s not working because you’re trying to read a value that doesn’t exist.
The
done
property doesn’t exist becausegetLocalStorageData
is an array of strings, not objects. This is because, in the add item handler, you’re only pushing strings.userEnteredValue
is just the string value from the input field. You should instead try pushing an object with avalue
property for the user entered value and adone
property to track if it’s done.Here’s an updated code that pushes objects and adds
.value
when needing the value.Define a task: You can create a task object with properties like task name and completion status. For example: var task = { name: "Task 1", completed: false };
Check the task completion status: You can use an if statement to check if the task is completed. For example: if (task.completed) { console.log("Task is completed"); } else { console.log("Task is not completed"); }
Mark the task as done: If the task is not marked as done, you can update its completion status. For example: task.completed = true; console.log("Task marked as done"); By setting task.completed to true, you indicate that the task is completed.