-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment1.js
More file actions
63 lines (45 loc) · 1.17 KB
/
Copy pathassignment1.js
File metadata and controls
63 lines (45 loc) · 1.17 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Assignment 1:
https://github.com/Devbootcamp/object-oriented-javascript-todos
*/
function Task(id, description, completed = false){
this.id = id;
this.description = description;
this.completed = completed;
};
Task.prototype.complete = function(){
this.completed = true;
}
function TodoList(){
this.tasks = [];
this.lastItemId = 0;
};
//methods
TodoList.prototype.add = function(taskDesc){
var taskId = this.lastItemId + 1;
this.tasks.push(new Task(taskId, taskDesc));
this.lastItemId = taskId;
}
TodoList.prototype.remove = function(task){
// if(Task.prototype.isPrototypeOf(task)){
let index = this.tasks.indexOf(task);console.log(index);
if(index != -1){
this.tasks.splice(index,1);
}
// }
}
TodoList.prototype.list = function(){
this.tasks.forEach(function(task) {
console.log('Task ' + JSON.stringify(task));
});
}
var groceryList = new TodoList();
groceryList.add('bread');
groceryList.add('cheese');
groceryList.add('milk');
// console.log(groceryList.tasks);
var breadTask = groceryList.tasks[0];
breadTask.complete();
groceryList.list();
groceryList.remove(breadTask);
groceryList.list();