-
Notifications
You must be signed in to change notification settings - Fork 0
/
aula73.js
79 lines (73 loc) · 2.01 KB
/
aula73.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
75
76
77
78
79
const teclasNum=[...document.querySelectorAll(".num")]
const teclasOp=[...document.querySelectorAll(".op")]
const teclaRes=document.querySelector(".res")
const display=document.querySelector(".display")
const ton=document.getElementById("ton")
const tlimpar=document.getElementById("tlimpar")
const tigual=document.getElementById("tigual")
const tcpy=document.getElementById("tcpy")
const teste=document.getElementById("teste")
const calc_aba=document.getElementById("calc_aba")
const calc=document.getElementById("calc")
const img_aba_calc=document.getElementById("img_aba_calc")
let sinal=false
let decimal=false
teclasNum.forEach((el)=>{
el.addEventListener("click",(evt)=>{
sinal=false
if(evt.target.innerHTML==","){
if(!decimal){
decimal=true
if(display.innerHTML=="0"){
display.innerHTML="0,"
}else{
display.innerHTML+=evt.target.innerHTML
}
}
}else{
if(display.innerHTML=="0"){
display.innerHTML=""
}
display.innerHTML+=evt.target.innerHTML
}
})
})
teclasOp.forEach((el)=>{
el.addEventListener("click",(evt)=>{
if(!sinal){
sinal=true
if(display.innerHTML=="0"){
display.innerHTML=""
}
if(evt.target.innerHTML=="x"){
display.innerHTML+="*"
}else{
display.innerHTML+=evt.target.innerHTML
}
}
})
})
tlimpar.addEventListener("click",(evt)=>{
sinal=false
decimal=false
display.innerHTML="0"
})
tigual.addEventListener("click",(evt)=>{
sinal=false
decimal=false
const res=eval(display.innerHTML)
display.innerHTML=res
})
tcpy.addEventListener("click",(evt)=>{
navigator.clipboard.writeText(display.innerHTML) //copia a la Area de Transferencia
})
calc_aba.addEventListener("click",(evt)=>{
calc.classList.toggle("calc_exibir")
if(calc.classList.contains("calc_exibir")){
//img_aba_calc.setAttribute("src","seta-esquerda.svg")
img_aba_calc.innerHTML="«"
}else{
//img_aba_calc.setAttribute("src","seta-direita.svg")
img_aba_calc.innerHTML="»"
}
})