-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (115 loc) · 2.74 KB
/
Copy pathscript.js
File metadata and controls
127 lines (115 loc) · 2.74 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var numero;
//----------------FUNÇOES DE FATORAÇÃO----------------------
function pegarElemento(elemento){
return document.getElementById(elemento).innerHTML;
}
function setarElemento(numero1){
document.getElementById('resultado').innerHTML = numero1;
}
//--------------FUNÇÕES ESSENCIAIS--------------------------
function inserir(numeroInput) {
if(pegarElemento('resultado') == "0"){
limpar();
numero = pegarElemento('resultado') ;
setarElemento(numero + numeroInput);
} else {
numero = pegarElemento('resultado') ;
setarElemento(numero + numeroInput);
}
}
function voltar() {
numero = pegarElemento('resultado');
setarElemento(numero.substring(0, numero.length - 1));
}
function limpar() {
setarElemento("");
}
function calcular() {
numero = pegarElemento('resultado');
if (numero) {
setarElemento(eval(numero));
}
}
/*
function raizQuadrada(numeroInsertInput) {
if (numeroInsertInput) {
document.getElementById("resultado").innerHTML = Math.sqrt(numeroInsertInput);
}
}*/
document.addEventListener("keydown", keyPush);
//-----------------FUNÇÕES DE EVENTO DE TECLAS----------------
function keyPush(event){
switch(event.keyCode){
case(48):
case(96):
inserir('0');
break;
case(49):
case(97):
inserir('1');
break;
case(50):
case(98):
inserir('2');
break;
case(51):
case(99):
inserir('3');
break;
case(52):
case(100):
inserir('4');
break;
case(53):
case(101):
inserir('5');
break;
case(54):
case(102):
inserir('6');
break;
case(55):
case(103):
inserir('7');
break;
case(56):
case(104):
inserir('8');
break;
case(57):
case(105):
inserir('9');
break;
case(106):
inserir('*');
break;
case(107):
case(187):
inserir('+');
break;
case(109):
case(189):
inserir('-');
break;
case(111):
case(191):
inserir('/');
break;
case(110):
case(188):
case(190):
inserir(',');
break;
case(46):
limpar();
case(8):
voltar();//MELHOR FAZER COM INPUT NO HTML PQ PODE CLICAR ONDE SE QUER ALTERAR
break;
case(13):
case(187):
calcular();
break;
default:
break;
}
}