Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions 01-js/hard/todo-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,64 @@
*/

class Todo {
constructor(){
this.todo = [];
}

add(todo){
this.todo.push(todo);
}

remove(index){
if(index>=0 && index<todo.length){
this.todo.splice(index,1);
}
else{
console.log("Index out of range");
}

}

update(index, updatedVal){
if(index>=0 && index< todo.length){
this.todo[index] = updatedVal;
}
else{
console.log("Index out of range");
}
}

getAll(){
console.log(todo);
}

get(){
if(index>=0 && index < todo.length){
console.log(this.todo(index)];
}
else{
console.log("Index out of range");
}
}

clear(){
this.todo = [];
}

let myTodo = new Todo();
myTodo.add("Completing assignment");
myTodo.add("Going to college");
myTodo.add("Completing 20+ videos target");
myTodo.add("Completing 0 to 1 as soon as possible");
myTodo.add("contributing on our group project");

myTodo.getAll();

myTodo.remove(2);
myTodo.getAll();
myTodo.update(2,"Coding atleast 3 hrs a day");
myTodo.getAll();
myTodo.get(2);


module.exports = Todo;