-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (43 loc) · 1.55 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Pobrane elementy
const btn = document.querySelector("button");
const input = document.querySelector("input");
const ul = document.querySelector(".added-tasks ul");
//Flaga
let checked = false;
const addTask = (e) => {
e.preventDefault();
const inputValue = input.value;
if (inputValue === "") return alert("Nic nie zostało wprowadzone");
else if (inputValue.length > 55) return alert("Zbyt dlugie zadanie");
const newListItem = document.createElement("li");
const iconBefore = document.createElement("i");
const iconAfter = document.createElement("i");
ul.appendChild(newListItem).textContent = inputValue;
newListItem.appendChild(iconAfter).className = "fas fa-times-circle";
newListItem.appendChild(iconBefore).className = "far fa-circle";
input.value = "";
document.querySelectorAll("i.fa-circle").forEach((icon) => {
icon.addEventListener("click", doneTask);
});
document.querySelectorAll("i.fa-times-circle").forEach((icon) => {
icon.addEventListener("click", deleteTask);
});
};
const doneTask = (e) => {
if (checked == false) {
checked = !checked;
const actualIcon = e.target;
actualIcon.parentNode.style.textDecoration = "line-through";
actualIcon.setAttribute("class", "far fa-check-circle");
} else {
checked = !checked;
const actualIcon = e.target;
actualIcon.parentNode.style.textDecoration = "none";
actualIcon.setAttribute("class", "far fa-circle");
}
};
const deleteTask = (e) => {
const deleteIcon = e.target;
deleteIcon.parentNode.remove();
};
btn.addEventListener("click", addTask);