-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
45 lines (37 loc) · 1.2 KB
/
scripts.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
const buttons = document.querySelectorAll('.btn')
const textarea = document.querySelector('textarea')
let chars = []
const deleteButton = document.querySelector('.backspace')
//const shiftButton = document.querySelector('.shift')
const spaceButton = document.getElementById("space")
const capslockButton = document.querySelector(".caps-lock")
const tabButton = document.querySelector(".tab")
const enterButton = document.querySelector(".enter")
buttons.forEach(btn => {
btn.addEventListener('click', () => {
textarea.value += btn.innerText
chars = textarea.value.split('')
//console.log(chars)
})
})
deleteButton.addEventListener("click", () => {
chars.pop()
textarea.value = chars.join('')
})
spaceButton.addEventListener("click", () => {
chars.push(' ')
textarea.value = chars.join('')
})
capslockButton.addEventListener("click", () => {
buttons.forEach(btn => {
btn.classList.toggle('upper')
})
})
tabButton.addEventListener("click", () => {
chars.push(' ')
textarea.value = chars.join('')
})
enterButton.addEventListener("click", () => {
chars.push('\n')
textarea.value = chars.join('')
})