London | 26-ITP-Jan | Carlos Abreu |Sprint 3 | Todo List#1147
London | 26-ITP-Jan | Carlos Abreu |Sprint 3 | Todo List#1147carlosyabreu wants to merge 1 commit intoCodeYourFuture:mainfrom
Conversation
| // Append a new task to todos[] | ||
| export function addTask(todos, task, completed = false) { | ||
| todos.push({ task, completed }); | ||
| export function addTask(todos, task, completed = false, deadline = null) { |
There was a problem hiding this comment.
How can a user choose a deadline for the task?
There was a problem hiding this comment.
If addTask function had a deadline parameter but the function body doesn't actually use it (it still only creates { task, completed }), there are a few ways a user could choose a deadline:
Modify the function to include deadline in the task object
First, it needs to update the function implementation to actually store the deadline:
// Updated todos.mjs
export function addTask(todos, task, completed = false, deadline = null) {
todos.push({ task, completed, deadline });
}
Then a user could specify a deadline when calling the function:
// Pass deadline as the 4th parameter
const deadline = new Date("2026-12-31");
Todos.addTask(todos, "Finish project", false, deadline);
// Or with different deadlines
Todos.addTask(todos, "Morning meeting", false, new Date("2026-04-07T09:00:00"));
Todos.addTask(todos, "Submit report", false, new Date("2026-04-10"));
There was a problem hiding this comment.
How would an end user call a function when using the web page?
| for (let i = todos.length - 1; i >= 0; i--) { | ||
| if (todos[i].completed) { | ||
| todos.splice(i, 1); | ||
| } | ||
| } |
There was a problem hiding this comment.
This works correctly. You can also research build in array functions that allow you to filter elements
There was a problem hiding this comment.
Thank you for pointing that out.
Definitely I'll research that option of building an array functions that allows element filtering to expand my knowledge.
Learners, PR Template
Self checklist
Changelist
Todo list app PR for Sprint 3 of Data Groups module