Web Dev Practical File
Web Dev Practical File
<html lang="en">
<head>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
integrity="sha512-
iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<title>Todo_List</title>
</head>
<body>
<header>
<h1>Todo List</h1>
</header>
<form>
</button>
<div class="select">
<option value="all">All</option>
<option value="completed">Completed</option>
<option value="uncompleted">Uncompleted</option>
</select>
</div>
</form>
<div class="todo-container">
<ul class="todo-list"></ul>
</div>
<script src="js/app.js"></script>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
body {
color: white;
header {
font-size: 1.5rem;
header,
form {
min-height: 20vh;
display: flex;
justify-content: center;
align-items: center;
form input,
form button {
padding: 0.5rem;
font-size: 2rem;
border: none;
border-radius: 0.1rem;
background: white;
outline: none;
border: none;
}
form button {
color: #ce6e54;
background: white;
cursor: pointer;
form button:hover {
background-color: #ce6e54;
color: white;
.todo-container {
display: flex;
justify-content: center;
align-items: center;
.todo-list {
min-width: 30%;
list-style: none;
.todo {
margin: 0.5rem;
background: white;
border-radius: 0.2rem;
color: black;
font-size: 1.5rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.todo li {
flex: 1;
.fall {
opacity: 0;
.trash-btn,
.complete-btn {
background: #ff6f47;
color: white;
border: none;
padding: 1rem;
cursor: pointer;
font-size: 1rem;
.complete-btn {
background: lightseagreen;
.fa-trash,
.fa-check {
pointer-events: none;
.completed {
text-decoration: line-through;
opacity: 0.5;
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
box-shadow: none;
border: 0 !important;
background-image: none;
.select {
margin: 1rem;
position: relative;
overflow: hidden;
select {
border-radius: 0.2rem;
color: #ff6f47;
width: 10rem;
cursor: pointer;
padding: 1rem;
.select::after {
content: "\25BC";
position: absolute;
background: #ff6f47;
top: 0;
right: 0;
padding: 1rem;
pointer-events: none;
cursor: pointer;
}
JAVA-SCRIPT
//Selectors:
const todoInput = document.querySelector(".todo-input");
const todoButton = document.querySelector(".todo-btn");
const todoList = document.querySelector(".todo-list");
const filterOption = document.querySelector(".filter-todo");
//Event Listeners:
document.addEventListener("DOMContentLoaded", getTodos);
todoButton.addEventListener("click", addTodo);
todoList.addEventListener("click", deleteCheck);
filterOption.addEventListener("click", filterTodo);
//Functions:
function addTodo(event) {
//prevent form from submitting.
event.preventDefault();
//create div element
const todoDiv = document.createElement("div");
//add todo class to that div.
todoDiv.classList.add("todo");
//Append Child:
todoDiv.appendChild(newTodo);
//check button:
const completedButton = document.createElement("button");
completedButton.innerHTML = "<i class='fas fa-check'></i>";
completedButton.classList.add("complete-btn");
todoDiv.appendChild(completedButton);
//delete button:
const trashButton = document.createElement("button");
trashButton.innerHTML = "<i class='fas fa-trash'></i>";
trashButton.classList.add("trash-btn");
todoDiv.appendChild(trashButton);
//Append to list:
todoList.appendChild(todoDiv);
function deleteCheck(e) {
const item = e.target;
//Delete todo:
if (item.classList[0] === "trash-btn") {
const todo = item.parentElement;
//Animation:
todo.classList.add("fall");
removeLocalTodos(todo);
todo.addEventListener("transitionend", function () {
todo.remove();
});
}
//Check mark:
if (item.classList[0] === "complete-btn") {
const todo = item.parentElement;
todo.classList.toggle("completed");
}
}
function filterTodo(e) {
const todos = todoList.childNodes;
todos.forEach(function (todo) {
switch (e.target.value) {
case "all":
todo.style.display = "flex";
break;
case "completed":
if (todo.classList.contains("completed")) {
todo.style.display = "flex";
} else {
todo.style.display = "none";
}
break;
case "uncompleted":
if (!todo.classList.contains("completed")) {
todo.style.display = "flex";
} else {
todo.style.display = "none";
}
break;
case "default":
break;
}
});
}
//Save locally:
function saveLocalTodos(todo) {
//Check if we already have something:
let todos;
if (localStorage.getItem("todos") === null) {
todos = [];
} else {
todos = JSON.parse(localStorage.getItem("todos"));
}
todos.push(todo);
localStorage.setItem("todos", JSON.stringify(todos));
}
function getTodos() {
let todos;
todos.forEach(function (todo) {
const todoDiv = document.createElement("div");
//add todo class to that div.
todoDiv.classList.add("todo");
//check button:
const completedButton = document.createElement("button");
completedButton.innerHTML = "<i class='fas fa-check'></i>";
completedButton.classList.add("complete-btn");
todoDiv.appendChild(completedButton);
//delete button:
const trashButton = document.createElement("button");
trashButton.innerHTML = "<i class='fas fa-trash'></i>";
trashButton.classList.add("trash-btn");
todoDiv.appendChild(trashButton);
//Append to list:
todoList.appendChild(todoDiv);
});
}
function removeLocalTodos(todo) {
let todos;
<library>
<book>
<author>Douglas Crockford</author>
<published>2008</published>
</book>
<book>
<title>Eloquent JavaScript</title>
<author>Marijn Haverbeke</author>
<published>2011</published>
</book>
<book>
<author>Kyle Simpson</author>
<published>2014</published>
</book>
</library>
function fetchBooks() {
xhr.onreadystatechange = function () {
output += '</ul>';
document.getElementById('books').innerHTML = output;
};
xhr.send();
fetchBooks();
<div id="books"></div>
RSS
npm init
const fs = require('fs');
feed_url: 'https://example.com/rss',
site_url: 'https://example.com',
});
feed.item({
url: 'https://example.com/item1',
});
feed.item({
url: 'https://example.com/item2',
})
fs.writeFileSync('rss.xml', xml);
node rss-generator.js
OUTPUT