-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.23 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
// set event on all buttons
for (let number of document.querySelectorAll(".teclado input")) {
if ( number.value !== "=" ) {
number.addEventListener('click', function() {
let display = document.getElementById('display');
let [...list] = display.value;
let pointExists = list.filter( value => value === '.' ).length > 0;
if ( !(this.value === '.' && pointExists) ) {
display.value += this.value;
}
});
}
}
// clean display
document.querySelector("input[name='clean']").onclick = function () {
let display = document.getElementById('display');
display.value = '';
let output = document.getElementById('output');
output.value = '';
};
// func deus
document.querySelector("input[name='=']").onclick = function() {
let display = document.getElementById('display');
let output = document.getElementById('output');
if (display.value) {
try {
let result = new Function("return "+display.value);
output.value = result();
} catch (error) {
output.value = 'NÃO SUPORTADO';
console.error(error);
}
return;
}
output.value = 'Entrada inválida.';
}