javascriptbeginner10 minutes
Simple To-Do List App in JavaScript
Create a basic to-do list application where users can add tasks, mark them as completed, and see the updated list.
Challenge prompt
Build a function that manages a to-do list. Your function should allow adding new tasks and marking tasks as completed by their name. It should return an updated array of task objects, where each task has a name and a completed status (true/false). Initially, all tasks are incomplete. Given an initial list of tasks, implement two functions: addTask(taskName) and completeTask(taskName).
Guidance
- • Use an array to store task objects with properties 'name' and 'completed'.
- • The addTask function should add a new task with 'completed' set to false.
- • The completeTask function should find the task by name and change its completed status to true.
Hints
- • Remember to check if a task already exists before adding it.
- • Use array methods like push() and find() or findIndex() to help manipulate the tasks.
Starter code
const tasks = [];
function addTask(taskName) {
// your code here
}
function completeTask(taskName) {
// your code here
}Expected output
[{ name: 'Buy milk', completed: true }, { name: 'Walk dog', completed: false }]
Core concepts
arraysobjectsfunctions
Challenge a Friend
Send this duel to someone else and see if they can solve it.