Build a Task Management CLI Mini Project
Create a simple command-line task manager in JavaScript that allows users to add, remove, list, and mark tasks as complete. This mini-project will help you practice array manipulation, object handling, and implementing multi-step logic.
Challenge prompt
Write a JavaScript function 'taskManager' that returns an object with methods to manage a list of tasks. The task manager should support the following methods: addTask(description), removeTask(index), markComplete(index), and listTasks(). Tasks should be stored as objects with properties: id, description, and completed (boolean). The listTasks method should output all tasks showing their id, description, and status (Completed or Pending). Ensure the task ids increment automatically starting from 1.
Guidance
- • Use an array to store the tasks inside your task manager object.
- • Each task should be an object with id, description, and completed properties.
- • Increment task ids automatically as new tasks are added.
- • Update the completed property when marking a task as complete.
Hints
- • Use closures to keep the task list private within the taskManager function.
- • Remember array methods like push(), splice(), and map() for managing tasks.
- • Format the output of listTasks for clear readability.
Starter code
function taskManager() {
// Your code here
}
const manager = taskManager();
manager.addTask('Finish homework');
manager.addTask('Clean room');
manager.listTasks();Expected output
1. Finish homework - Pending 2. Clean room - Pending
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.