[go: up one dir, main page]

0% found this document useful (0 votes)
19 views1 page

Todo App Code

This document contains a JavaScript code for a simple To-Do app that allows users to add, list, delete tasks, or quit the application. It utilizes a loop to continuously prompt the user for input until they choose to quit. The app manages tasks using an array and provides feedback for each action taken by the user.

Uploaded by

ranjitvicky745
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Todo App Code

This document contains a JavaScript code for a simple To-Do app that allows users to add, list, delete tasks, or quit the application. It utilizes a loop to continuously prompt the user for input until they choose to quit. The app manages tasks using an array and provides feedback for each action taken by the user.

Uploaded by

ranjitvicky745
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JavaScript To-Do App Code

let todo = [];

let req = prompt("Please enter your request (add, list, delete, quit):");

while (true) {
if (req === "quit") {
console.log("You are quitting the app.");
break;
} else if (req === "list") {
console.log("___________________________________________");
for (let i = 0; i < todo.length; i++) {
console.log(i + ":", todo[i]);
}
console.log("___________________________________________");
} else if (req === "add") {
let task = prompt("Please enter your task:");
todo.push(task);
console.log("Task successfully added.");
} else if (req === "delete") {
let del = parseInt(prompt("Please enter the index of the task you want to delete:"));
if (!isNaN(del) && del >= 0 && del < todo.length) {
todo.splice(del, 1);
console.log("Task deleted.");
} else {
console.log("Invalid index.");
}
} else {
console.log("Wrong request. Please enter add, list, delete, or quit.");
}

req = prompt("Please enter your request:");


}

You might also like