Last active
October 21, 2019 18:42
-
-
Save lolwuz/690b70ac100082bf1713dd18da4ef51d to your computer and use it in GitHub Desktop.
Todos
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 todos = []; | |
function addTodo() { | |
var name = document.getElementById("form-name").value; | |
var newTodo = { | |
id: guidGenerator(), | |
name: name, | |
isDone: false | |
}; | |
todos.push(newTodo); | |
renderTodos(); | |
} | |
function removeTodo(id) { | |
for (var i = 0; i < todos.length; i++) { | |
var todo = todos[i]; | |
if (todo.id === id) { | |
todos.splice(i, 1); | |
} | |
} | |
renderTodos(); | |
} | |
function setTodo(id) { | |
for (var i = 0; i < todos.length; i++) { | |
var todo = todos[i]; | |
if (todo.id === id) { | |
todo.isDone = !todo.isDone; | |
} | |
} | |
renderTodos(); | |
} | |
function guidGenerator() { | |
var S4 = function() { | |
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); | |
}; | |
return ( | |
S4() + | |
S4() + | |
"-" + | |
S4() + | |
"-" + | |
S4() + | |
"-" + | |
S4() + | |
"-" + | |
S4() + | |
S4() + | |
S4() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment