-
Notifications
You must be signed in to change notification settings - Fork 0
/
task-list.js
47 lines (42 loc) · 1.01 KB
/
task-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Browser-side JavaScript (ECMAScript 5)
var exit = false,
tasks = [];
function display_tasks() {
var response = "----------\n";
for(i=0; i < tasks.length; i++) {
response += (i+1) + ".) " + tasks[i] + "\n";
}
response += "----------";
alert(response);
}
function add_task() {
var task = prompt("Type a new task:");
tasks.push(task);
display_tasks();
}
function remove_task() {
display_tasks();
var index = parseInt(prompt("Type task number to remove:")) - 1;
tasks.splice(index, 1);
display_tasks();
}
while (exit === false) {
var choice = parseInt(prompt("Please enter a number from the following choices: 1. Insert a new task, 2. Remove a task, 3. List all tasks, 4. exit this program"));
if (choice === 1) {
add_task();
}
else if (choice === 2) {
remove_task();
}
else if (choice === 3) {
display_tasks();
}
else if (choice === 4) {
alert("Exiting...");
exit = true;
window.close();
}
else {
alert("sorry didn't recognize that input");
}
}