Skip to content

Instantly share code, notes, and snippets.

@lolwuz
Last active October 21, 2019 18:42
Show Gist options
  • Save lolwuz/690b70ac100082bf1713dd18da4ef51d to your computer and use it in GitHub Desktop.
Save lolwuz/690b70ac100082bf1713dd18da4ef51d to your computer and use it in GitHub Desktop.
Todos
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