A Pen by Richard Prins on CodePen.
Created
March 14, 2019 01:49
-
-
Save RichardSPrins/efbd877598b6ce73e4dd314b394a958a to your computer and use it in GitHub Desktop.
Practical JS - Watch and Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="style.css"> | |
<script type="text/javascript" src="script.js"></script> | |
</head> | |
<body> | |
<h1>Hello Scott!</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var todoList = { | |
todos: [], | |
displayTodos: function() { | |
if (this.todos.length === 0) { | |
console.log("Your Todo List is empty!"); | |
} else { | |
console.log("My Todos:"); | |
for (var i = 0; i < this.todos.length; i++) { | |
if (this.todos[i].completed === true) { | |
console.log("(x)", this.todos[i].todoText); | |
} else { | |
console.log("( )", this.todos[i].todoText); | |
} | |
} | |
} | |
}, | |
addTodo: function(todoText) { | |
this.todos.push({ | |
todoText: todoText, | |
completed: false | |
}); | |
this.displayTodos(); | |
}, | |
changeTodo: function(position, todoText) { | |
this.todos[position].todoText = todoText; | |
this.displayTodos(); | |
}, | |
deleteTodo: function(position) { | |
this.todos.splice(position, 1); | |
this.displayTodos(); | |
}, | |
toggleCompleted: function(position) { | |
var todo = this.todos[position]; | |
todo.completed = !todo.completed; | |
this.displayTodos(); | |
}, | |
toggleAll: function() { | |
var totalTodos = this.todos.length; | |
var completedTodos = 0; | |
for (var i = 0; i < totalTodos; i++) { | |
if (this.todos[i].completed === true) { | |
completedTodos++; | |
} | |
} | |
if (completedTodos === totalTodos) { | |
for (var i = 0; i < totalTodos; i++) { | |
this.todos[i].completed = false; | |
} | |
} else { | |
for (var i = 0; i < totalTodos; i++) { | |
this.todos[i].completed = true; | |
} | |
} | |
this.displayTodos(); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Style Goes Here*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment