Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define an array to store tasks
- let tasks = [];
- // Function to add a task to the list
- function addTask(task) {
- tasks.push(task);
- console.log(`Task "${task}" added.`);
- }
- // Function to remove a task from the list
- function removeTask(task) {
- const index = tasks.indexOf(task);
- if (index !== -1) {
- tasks.splice(index, 1);
- console.log(`Task "${task}" removed.`);
- } else {
- console.log(`Task "${task}" not found.`);
- }
- }
- // Function to display all tasks
- function displayTasks() {
- if (tasks.length === 0) {
- console.log('Task list is empty.');
- } else {
- console.log('Tasks:');
- tasks.forEach((task, index) => {
- console.log(`${index + 1}. ${task}`);
- });
- }
- }
- // Add tasks to the list
- addTask('Complete homework');
- addTask('Buy groceries');
- addTask('Call friend');
- // Display initial list of tasks
- displayTasks();
- // Remove a task from the list
- removeTask('Buy groceries');
- // Display updated list of tasks
- displayTasks();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement