-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.js
More file actions
62 lines (48 loc) · 1.78 KB
/
Display.js
File metadata and controls
62 lines (48 loc) · 1.78 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
class Dispaly{
constructor(dispayValorActual, dispayValorAnterior){
this.dispayValorActual = dispayValorActual;
this.dispayValorAnterior = dispayValorAnterior;
this.calculadora = new Calculadora();
this.tipoOperacion = undefined;
this.valorActual = '';
this.valorAnterior = '';
this.signo = {
sumar: "+",
restar: "-",
multiplicar: "x",
dividir: "%",
}
}
borrar(){
this.valorActual = this.valorActual.toString().slice(0, -1);
this.imprimirValres();
}
borrarTodo(){
this.valorAnterior = "";
this.valorActual = "";
this.tipoOperacion = undefined;
this.imprimirValres();
}
computar(tipo){
this.tipoOperacion !== "igual" && this.calcular();
this.tipoOperacion = tipo;
this.valorAnterior = this.valorActual || this.valorAnterior;
this.imprimirValres();
this.valorActual = "";
}
agregarNumero(numero){
if(numero === "." && this.valorActual.includes("."))return
this.valorActual = this.valorActual.toString() + numero;
this.imprimirValres();
}
imprimirValres(){
this.dispayValorActual.textContent = this.valorActual;
this.dispayValorAnterior.textContent = `${this.valorAnterior} ${this.signo[this.tipoOperacion] || ""}`;
}
calcular(){
const valorAnterior = parseFloat(this.valorAnterior) ;
const valorActual = parseFloat(this.valorActual) ;
if(isNaN(valorActual) || isNaN(valorAnterior)) return
this.valorActual = this.calculadora[this.tipoOperacion](valorAnterior, valorActual);
}
}