-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
90 lines (83 loc) · 2.76 KB
/
main.js
File metadata and controls
90 lines (83 loc) · 2.76 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
var operA;
var operaB;
var simbolo;
var res = 0;
const resultado = document.querySelector(".Resultado");
const mostrar1 = document.getElementById("mostrar1");
const mostrar2 = document.getElementById("mostrar2");
const cero = document.querySelector(".cero");
const uno = document.querySelector(".uno");
const dos = document.querySelector(".dos");
const tres = document.querySelector(".tres");
const cuatro = document.querySelector(".cuatro");
const cinco = document.querySelector(".cinco");
const seis = document.querySelector(".seis");
const siete = document.querySelector(".siete");
const ocho = document.querySelector(".ocho");
const nueve = document.querySelector(".nueve");
const suma = document.querySelector(".suma");
const resta = document.querySelector(".resta");
const multiplicacion = document.querySelector(".multiplicacion");
const division = document.querySelector(".division");
const borrrar = document.querySelector(".C");
const resetear = document.querySelector(".CE");
const igual = document.querySelector(".igual");
cero.addEventListener("click", () => mostrar("0"));
uno.addEventListener("click", () => mostrar("1"));
dos.addEventListener("click", () => mostrar("2"));
tres.addEventListener("click", () => mostrar("3"));
cuatro.addEventListener("click", () => mostrar("4"));
cinco.addEventListener("click", () => mostrar("5"));
seis.addEventListener("click", () => mostrar("6"));
siete.addEventListener("click", () => mostrar("7"));
ocho.addEventListener("click", () => mostrar("8"));
nueve.addEventListener("click", () => mostrar("9"));
borrrar.addEventListener("click", limpiar);
resetear.addEventListener("click", reset);
suma.addEventListener("click", () => operacion("+"));
resta.addEventListener("click", () => operacion("-"));
multiplicacion.addEventListener("click", () => operacion("*"));
division.addEventListener("click", () => operacion("/"));
igual.addEventListener("click", equal);
function mostrar(num) {
mostrar2.textContent = mostrar2.textContent + num;
}
function limpiar() {
mostrar2.textContent = "";
}
function reset() {
mostrar2.textContent = "";
mostrar1.textContent = "";
operA = 0;
operaB = 0;
simbolo = "";
}
function operacion(sim) {
operA = mostrar2.textContent;
simbolo = sim;
mostrar1.textContent = operA + simbolo;
limpiar();
}
function equal() {
operaB = mostrar2.textContent;
resolver();
mostrar1.textContent = operA + simbolo + operaB;
}
function resolver() {
switch (simbolo) {
case "+":
res = parseInt(operA) + parseInt(operaB);
break;
case "-":
res = parseInt(operA) - parseInt(operaB);
break;
case "*":
res = parseInt(operA) * parseInt(operaB);
break;
case "/":
res = parseInt(operA) / parseInt(operaB);
break;
}
mostrar2.textContent = res;
console.log(res);
}