Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submissions for taiwo famakinde #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions taiwo-famakinde/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="shoppinglist.css">
<title>Shopping list</title>
</head>

<body>
<h2>My Shopping & To-Do List</h2>

<form class="form-group">
<input id="item-form" name="item-name" type="text" class="item_input" placeholder="Item title" />
<input id="qty-form" name="quantity" type="text" class="qty_input" placeholder="Quantity" />
<input id="desc-form" name="description" type="text" class="desc_input" placeholder="Description" />

</form>

<button class="todo_button" id="add-button">+</button>

<div class="todo_container">
<h2 style="text-align: center;">To-Do List</h2>
<ul class="todo_list">
<li class="todo_info">

</li>

</ul>
</div>

<script src="shoppinglist.js"></script>

</body>

</html>
90 changes: 90 additions & 0 deletions taiwo-famakinde/shoppinglist.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
body{
text-align: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
margin: 100px;
}

h2{
color: darkblue;
font-weight: lighter;
padding: 10px;
margin-bottom: 7px;
}

input{
padding: 10px 15px;
font-size: 16px;
border-radius: 8px;
border: 1px solid darkblue;
}

/* forms to fill */
.form-group{
/* border: 1px solid gray; */
border-radius: 8px;
padding-top: 20px;
padding-bottom: 10px;
align-items: center;
/* margin-left: 100px;
margin-right: 100px; */
/* margin-bottom: 50px; */
}

#item-form, #qty-form, #desc-form{
margin-top: 10px;
margin-bottom: 10px;
align-items: center;
/* padding-bottom: 20px; */
/* padding-right: 100px; */
}

button{
background-color: darkblue;
color: white;
border-radius: 3px;
font-size: 20px;
margin-bottom: 30px;
}


/* done list */
.todo_container{
border: 1px solid darkblue;
border-radius: 8px;
padding: 0px;
text-align: center;
/* margin-left: 300px;
margin-right: 300px;
margin-top: 0px; */
border-top: 1px solid darkblue;
border-bottom: 1px solid darkblue;
}

li{
margin: 10px;
padding: 0px;
}

.todo_list{
display: block;
text-align: left;
list-style-type: none;

}

/* .todo_container, todo_list{
display: flex;
} */



@media only screen and (min-width: 768px) {
main{
display: block;
}

.columns-desktop{
display: block;
}
}
81 changes: 81 additions & 0 deletions taiwo-famakinde/shoppinglist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//query selectors to get the values using the Classnames of the elements
const itemInput = document.querySelector('.item_input');
const qtyInput = document.querySelector('.qty_input');
const descInput = document.querySelector('.desc_input');
const todoButton = document.querySelector('.todo_button');
const todoList = document.querySelector('.todo_list');

//todo event listeners for add and delete buttons
todoButton.addEventListener("click", addTodo)
todoList.addEventListener("click", deleteTodo)

//function to create a list of a single Todo Item
function createTodoDiv() {

const todoDiv = document.createElement('div')

//for item Item
const itemItem = document.createElement('li');
itemItem.innerText = itemInput.value
todoDiv.appendChild(itemItem)

//for qty Item
const qtyItem = document.createElement('li');
qtyItem.innerText = qtyInput.value
todoDiv.appendChild(qtyItem)

//for desc Item
const descItem = document.createElement('li');
descItem.innerText = descInput.value
todoDiv.appendChild(descItem)
return todoDiv
}
function addTodo(event) {
//i have forgotten what this thing does but i know you always have to put it when submitting a form
event.preventDefault();

//create todo DIV
const todoDiv = document.createElement('div');
todoDiv.classList.add('todo');

//create todo List
const newTodo = document.createElement('div');
newTodo.appendChild(createTodoDiv());
newTodo.classList.add('todo_item');
todoDiv.appendChild(newTodo);
todoDiv.appendChild(deleteButton());

//add todoList to todo Div
todoList.appendChild(todoDiv);

//Clear form input values
clearInput()

}

function deleteButton() {
const deleteButton = document.createElement('button');
deleteButton.innerHTML = 'Done';
deleteButton.classList.add('delete_btn');
return deleteButton;
}

//to reset the form to empty input
function clearInput() {
itemInput.value = ""
qtyInput.value = ""
descInput.value = ""
}

//the "event" is automatically available to this "deleteTodo" function because you have registered "deleteTodo"
// with eventlisteners on line 27
function deleteTodo(event) {
//to fetch the item your mouse is hovering on / targeting
const item = event.target;

//to delete item from the list by checking if the targeted item has class "delete_btn"
if (item.classList[0] === "delete_btn") {
const todo = item.parentElement;
todo.remove();
}
}