-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 1.13 KB
/
index.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
const dropDown = document.querySelector('#dropDown')
const open = document.querySelector('.open')
const close = document.querySelector('.close')
const priceSwitch = document.querySelector('.switch input[type=checkbox]')
const prices = document.querySelectorAll('.price h1')
open.onclick = function () {
open.classList.toggle('hide')
close.classList.toggle('hide')
dropDown.classList.remove('hide')
dropDown.classList.add('flex')
}
close.onclick = function () {
open.classList.toggle('hide')
close.classList.toggle('hide')
dropDown.classList.add('hide')
dropDown.classList.remove('flex')
}
priceSwitch.onchange = () => {
prices.forEach((price) => {
if (priceSwitch.checked) {
let remainder = price.textContent.replace('$', ' ') % 10
if (remainder !== 9) {
price.textContent = price.textContent + '0'
} else {
price.textContent = price.textContent + remainder
}
} else {
price.textContent = price.textContent.slice(0, -1)
}
})
}
window.addEventListener('DOMContentLoaded', function () {
this.document.querySelector('.time').textContent = new Date().getFullYear()
})