Created
December 10, 2021 17:46
-
-
Save andygimma/cad49e786f2ef7fc40d28cd750fe79e4 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div> | |
<form> | |
<input type="text" id="todo-text-bar"/> | |
<button id="todo-button">Add Todo</button> | |
</form> | |
<div id="todo-list-container"></div> | |
</div> | |
<script> | |
// Nouns | |
// #todo-text-bar | |
// #todo-text-button | |
// #todo-list-container | |
// #todo-list-item | |
// Verbs | |
// - click the button * | |
// - read text in text bar * | |
// - adds text from text bar to some list * | |
// - clear the text bar * | |
// - display the list in the container so the user can see their list items | |
const todoButton = document.getElementById('todo-button') | |
const todoTextBar = document.getElementById('todo-text-bar') | |
const todoListContainer = document.getElementById('todo-list-container') | |
const todoList = [] | |
todoButton.addEventListener("click", function(event){ | |
event.preventDefault() | |
const todo = todoTextBar.value | |
todoTextBar.value = "" | |
todoList.push(todo); | |
for (x = 0; x < todoList.length; x++) { | |
const item = todoList[x] | |
const textnode = document.createTextNode(item) | |
todoListContainer.appendChild(textnode) | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment