changed up steps 1,2,3 to have exercises. removed js implementation of todo app

This commit is contained in:
Micah Godbolt
2019-03-01 20:19:31 -08:00
parent c21b92c30f
commit 9ff15add37
33 changed files with 454 additions and 1426 deletions

View File

@@ -1,28 +0,0 @@
## Exercise
Open up the [Todo JavaScript Exercise Page](http://localhost:8080/step1-03/exercise/)
Open the `index.html` file in this exercise folder.
### Update Navigation
1. Add an `onclick` attribute to all three buttons in the navigation.
2. In each `onclick` call the `filter` function. In our function we need a reference to the clicked button, so pass in the keyword `this` as the only parameter.
### Complete the `updateRemaining` function
1. Using `querySelector`, get a reference to the span with the `remaining` class, and store it in a variable .
2. Use [`querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) to get all of the todos.
3. Set the `innerText` of the remaining span to the length of those todos.
4. Add `updateRemaining()` to the end of the `addTodo` function.
### Write a `clearCompleted` function
1. Get a reference to all of the todos with [`querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll).
2. Use a `for (let todo of todos)` loop to iterate over each todo.
3. Inside the for loop write an `if` statement to test if the `input` inside of the todo has a checked value of true.
> Hint: you can use `querySelector` on any HTML element to find matching child elements.
4. Call `todo.remove()` for any todo whose input is checked.
5. After the loop is done, run `updateRemaining()`.
6. Attach `clearCompleted()` function to the `onclick` of the footer button.
7. Test it out!

View File

@@ -1,80 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./style.css" />
</head>
<style>
label,
button {
display: block;
margin-bottom: 10px;
}
</style>
<body>
<header>
<h1>todos - step1-03 exercise</h1>
<div class="addTodo">
<input class="textfield" placeholder="add todo" />
<button onclick="addTodo()" class="submit">Add</button>
</div>
<nav class="filter">
<button class="selected">all</button>
<button>active</button>
<button>completed</button>
</nav>
</header>
<label><input type="checkbox" />Ice cream</label>
<label><input type="checkbox" />Pizza</label>
<label><input type="checkbox" />Tacos</label>
<label><input type="checkbox" />Meatloaf</label>
<label><input type="checkbox" />Brocolli</label>
<ul class="todos">
<li class="todo">
<label><input type="checkbox" /> <span class="title"> Todo 1 </span></label>
</li>
<li class="todo">
<label><input type="checkbox" /> <span class="title"> Todo 2 </span></label>
</li>
<li class="todo">
<label><input type="checkbox" /> <span class="title"> Todo 3 </span></label>
</li>
<li class="todo">
<label><input type="checkbox" /> <span class="title"> Todo 4 </span></label>
</li>
</ul>
<footer>
<span><i class="remaining">4</i> items left</span>
<button class="submit">Clear Completed</button>
</footer>
<button>Display Your Favorites</button>
<div class="favorites"></div>
</body>
<script type="text/javascript">
function clearInput(selector) {
document.querySelector(selector).value = '';
}
function getTodoText() {
return document.querySelector('.textfield').value;
}
function updateRemaining() {
}
function addTodo() {
const todo = document.querySelector('.todo');
const newTodo = todo.cloneNode(true);
newTodo.querySelector('.title').innerText = getTodoText();
todo.parentElement.insertBefore(newTodo, todo);
clearInput('.textfield');
}
// clearCompleted
function filter(button) {
document.querySelector('.selected').classList.remove('selected');
button.classList.add('selected');
const filterName = button.innerText;
for (let todo of document.querySelectorAll('.todo')) {
const checked = todo.querySelector('input').checked === true;
if (filterName === 'all') {
todo.hidden = false;
} else if (filterName === 'active') {
todo.hidden = checked;
} else if (filterName === 'completed') {
todo.hidden = !checked;
<script>
function getFavs() {
let favList = [];
const inputs = document.querySelectorAll('input');
for (const input of inputs) {
if (input.checked === true) {
favList.push(input.parentNode.textContent);
}
}
document.querySelector('.favorites').textContent = favList.join(' ');
}
let button = document.querySelector('button');
button.addEventListener('click', getFavs);
</script>
</html>

View File

@@ -1,49 +0,0 @@
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
width: 400px;
margin: 20px auto;
}
h1 {
text-align: center;
}
.addTodo {
display: flex;
}
.textfield {
flex-grow: 1;
margin-right: 10px;
}
.submit {
border: none;
padding: 5px 10px;
}
.filter {
margin: 10px 0 0;
}
.filter button {
background: transparent;
border: none;
}
.filter .selected {
border-bottom: 2px solid blue;
}
.todos {
list-style: none;
padding: 0;
}
footer {
display: flex;
}
footer span {
flex-grow: 1;
}