-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.js
67 lines (52 loc) · 1.45 KB
/
calculate.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
var number = Array.from(document.getElementsByClassName('number'));
var operator = Array.from(document.getElementsByClassName('operator'));
var inputObj = document.getElementById('window');
var inputOp = document.getElementById('op-window');
var borrar = document.getElementById('delete');
var resulta = document.getElementById('result');
var equal = document.getElementById('eq-operator');
//var selectOperator;
var firstNumber;
//var firstOperatorNumber;
var secondNumber;
var result;
function touchNumber(){
number.forEach((numberElement) => {
numberElement.addEventListener('click', function(event){
var inputValue = inputObj.value;
inputValue += numberElement.value;
inputObj.value = inputValue;
firstNumber = inputObj.value;
var num1 = parseFloat(firstNumber);
firstNumber = num1;
if(inputOp.value !== ""){
inputObj.value = "";
}
})
return numberElement.value;
})
}
function touchOperator(){
operator.forEach((operatorElement) =>{
operatorElement.addEventListener('click', function(event){
inputOp.value = operatorElement.value;
})
return operatorElement.value;
})
}
function final(){
}
function reset(){
borrar.addEventListener('click', function(event){
inputObj.value = "";
inputOp.value = "";
firstNumber = undefined;
});
}
function init(){
touchNumber();
reset();
touchOperator();
final();
}
init();