-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
74 lines (61 loc) · 2.32 KB
/
script.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
window.addEventListener("DOMContentLoaded", () => {
const hamburger = document.querySelector("#hamburger")
const hamburgerMenu = document.querySelector("#hamburger-menu")
const headerP = document.querySelector("#header-p")
const loveForm = document.querySelector("#love-form")
const love = document.querySelector("#love-form #love")
const loveUl = document.querySelector("#love-ul")
const buttons = document.querySelectorAll("#donate-section button")
const custom = document.querySelector("#custom")
let donation = document.querySelector("#donation")
let person = prompt("Enter your name cuzz!");
if (person != null) {
alert(`${person} Welcome to the neighborhood!`)
}
buttons.forEach((button) => {
button.addEventListener("click", updateTotal)
})
custom.addEventListener("blur", updateCustom)
function updateTotal(e) {
const amount = parseInt(e.target.value)
let newTotal = parseInt(donation.innerText) + amount
donation.innerText = `${newTotal} `
console.log(newTotal)
}
function updateCustom() {
let value = parseInt(custom.value) || 0
if (value >= 0) {
let newCustomTotal = parseInt(donation.innerText) + value
donation.innerText = `${newCustomTotal} `
}
custom.value = ""
}
hamburger.addEventListener("click", toggleHamburger)
hamburger.addEventListener("blur", removeHamburger)
loveForm.addEventListener("submit", showLove)
function toggleHamburger() {
hamburgerMenu.classList.toggle("invisible")
if (Array.from(hamburgerMenu.classList).includes("invisible")) {
headerP.classList.remove("invisible")
} else {
headerP.classList.add("invisible")
}
}
function removeHamburger() {
hamburgerMenu.classList.add("invisible")
if (Array.from(hamburgerMenu.classList).includes("invisible")) {
headerP.classList.remove("invisible")
} else {
headerP.classList.add("invisible")
}
}
function showLove(e) {
e.preventDefault();
const text = love.value
if (text.trim() !== "") {
const newLi = document.createElement("li")
newLi.innerText = text
loveUl.appendChild(newLi)
}
}
})