Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. var todoList = {
  2. todos: [],
  3. displayTodos: function() {
  4. if (this.todos.length === 0) {
  5. console.log('The list is empty.');
  6. } else {
  7. console.log('Todo List:');
  8. for (var i = 0; i < this.todos.length; i++) {
  9. if (this.todos[i].completed === true) {
  10. console.log('(X)', this.todos[i].info);
  11. } else {
  12. console.log('( )', this.todos[i].info);
  13. }
  14. }
  15. }
  16. },
  17. addTodos: function(todoText) {
  18. this.todos.push({
  19. info: todoText,
  20. completed: false //Boolean true or false
  21. });
  22. this.displayTodos();
  23. },
  24. changeTodo: function(position, todoText) {
  25. this.todos[position].info = todoText;
  26. this.displayTodos();
  27. },
  28. deleteTodo: function(position) {
  29. this.todos.splice(position, 1);
  30. this.displayTodos();
  31. },
  32. toggleCompleted: function(position) {
  33. var todo = this.todos[position];
  34. todo.completed = !todo.completed;
  35. this.displayTodos();
  36. }
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement