javascriptbeginner10 minutes

Build a Simple To-Do List App

Create a basic to-do list application in JavaScript where users can add, view, and remove tasks. This project helps beginners practice working with arrays, functions, and DOM manipulation.

Challenge prompt

Write a JavaScript function to manage a to-do list. Your code should allow adding new tasks to the list, displaying all current tasks, and removing a task by its name. You do not need to handle user input from HTML elements; focus on manipulating the task list using functions and arrays.

Guidance

  • Use an array to store the tasks.
  • Create functions: addTask(task), removeTask(task), and getTasks() to manage the list.
  • Use simple loops or array methods to find and remove tasks.

Hints

  • To add a task, use the array push() method.
  • To remove a task, find its index with indexOf() and then use splice().
  • getTasks() should return a copy of the array or the array itself to display current tasks.

Starter code

const tasks = [];

function addTask(task) {
  // Your code here
}

function removeTask(task) {
  // Your code here
}

function getTasks() {
  // Your code here
}

Expected output

addTask('Learn JavaScript'); addTask('Write a blog post'); console.log(getTasks()); // Output: ['Learn JavaScript', 'Write a blog post'] removeTask('Learn JavaScript'); console.log(getTasks()); // Output: ['Write a blog post']

Core concepts

ArraysFunctionsArray methodsBasic algorithmic thinking

Challenge a Friend

Send this duel to someone else and see if they can solve it.