-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
98 lines (68 loc) · 2.31 KB
/
calculator.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
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
import { clonage } from "./utiliteur";
// convention de nomage camelCase
// l'entete du calculator
class enteteCalulator {
constructor(objetHtml) {
this._objetHtml = objetHtml;
}
AddValue(valeur) {
}
getValue() {
let affiche = this._objetHtml;
let proposition = [];
let expression = [];
let resultat = []
for (let index = 0; index < affiche.children.length; index++) {
if (affiche.children[index].innerText != "+" && affiche.children[index].innerText != "*" && affiche.children[index].innerText != ")" && affiche.children[index].innerText != "(") {
if (affiche.children[index].style['border-top-color'] == "black") {
proposition.push("-" + affiche.children[index].innerText);
} else {
proposition.push(affiche.children[index].innerText);
}
}
}
expression = [].concat(proposition);
for (let i = 0; i < proposition.length; i++) {
if (proposition[i].length > 1) {
proposition[i] = proposition[i][1]
}
}
for (let j = 0; j < proposition.length; j++) {
for (let i = 0; i < proposition.length; i++) {
if (proposition[j] == proposition[i] && j != i) {
proposition.splice(i, 1)
}
}
}
// separation des elements
return [proposition, expression];
}
getObject() {
return this._objetHtml;
}
}
class calculator {
constructor(entete, objetHtml, buttons) {
this.listButton = buttons;
this._entete = entete;
this._objetHtml = objetHtml;
}
productionTableDeVerite() {
return this._entete.getValue()[0];
}
affichageTableDeVerite(tableAffichage) {
}
ecouterActionButtonNormal() {
let tampo = this._entete;
for (let i = 0; i < this.listButton.length - 1; i++) {
this.listButton[i].ecouterButton(tampo);
}
}
ecouterActionButtonOperator() {
let tam = this._entete;
this.listButton[this.listButton.length - 1].getObjetHtml().addEventListener('click', function () {
alert( tam.getValue()[0])
})
}
}
export { enteteCalulator, calculator }