Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active June 16, 2020 23:57
Show Gist options
  • Save harrisonmalone/eaa17b2432038c68eaf5123eec3e241c to your computer and use it in GitHub Desktop.
Save harrisonmalone/eaa17b2432038c68eaf5123eec3e241c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script defer src="./index.js"></script>
</head>
<body>
<h1>Number of tasks: 0</h1>
<input type="text" name="task" id="task">
<button>Add task</button>
<ol>
<!-- tasks will go here -->
</ol>
</body>
</html>
// selecting elements on the page
const button = document.querySelector("button")
const ol = document.querySelector("ol")
const input = document.querySelector("input")
const h1 = document.querySelector("h1")
const renderTasks = (task) => {
// .appendChild
// .innerHTML
ol.insertAdjacentHTML("beforeend", `
<li>${task}</li>
`)
}
const countTasks = () => {
const numOfTasks = ol.children.length
h1.textContent = `Number of tasks: ${numOfTasks}`
}
const handleClick = (e) => {
renderTasks(input.value)
input.value = ''
countTasks()
}
button.addEventListener("click", handleClick)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment