Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// Define an array to hold our tasks

let tasks = [];

// Function to add a task to the array


function addTask(task) {
tasks.push(task);
}

// Function to remove a task from the array


function removeTask(task) {
const index = tasks.indexOf(task);
if (index !== -1) {
tasks.splice(index, 1);
}
}

// Function to display all the tasks in the array


function displayTasks() {
console.log('Tasks:');
tasks.forEach((task, index) => {
console.log(`${index + 1}. ${task}`);
});
}

// Function to prompt the user to enter a task


function promptForTask() {
const task = prompt('Enter a task:');
if (task) {
addTask(task);
console.log(`Added task: ${task}`);
}
}

// Display the initial list of tasks


displayTasks();

You might also like