-
Notifications
You must be signed in to change notification settings - Fork 0
/
javaScript.js
139 lines (126 loc) · 4.12 KB
/
javaScript.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import calculate from "./functions/calculate.js";
import addNumber from "./functions/addNumber.js";
import remover from "./functions/remover.js";
import functionShowAble from "./functions/addFunctionShowAble.js";
import { resetCE, resetC } from "./functions/resets.js";
import togglePositivity from "./functions/togglePositivity.js";
import oneDividedByNumber from "./functions/oneDividedByNumber.js";
import numberSquared from "./functions/numberSquared.js";
import numberCubed from "./functions/numberCubed.js";
import root from "./functions/root.js";
import decimal from "./functions/decimal.js";
import percent from "./functions/percent.js";
import showHistory from "./functions/showHistory.js";
import showMemory from "./functions/showMemory.js";
import memoryHandler from "./functions/memoryHandler.js";
let numbers = [];
let actions = [];
let changedNumbers = true; //This is for determining whether user has intentionally pressed zero and wants to use it
let done = false;
let history = [];
let memory = [];
let currentShowHistory = true;
console.log({ "done is": done });
showHistory(history);
const calculateIt = () => {
if (numbers.length < 1 || actions.length < 1) return;
calculate(
numbers,
actions,
changedNumbers,
done,
history,
currentShowHistory
);
done = true;
};
const addNumberIt = (Event) => {
console.log(done);
addNumber(Event, done, numbers, actions, changedNumbers);
done = false;
changedNumbers = true;
};
const removerIt = () => {
remover();
};
const addFunctionShowAbleIt = (Event) => {
functionShowAble(Event, changedNumbers, numbers, actions, done);
};
const resetCIt = () => {
resetC(numbers, actions, done);
};
const resetCEIt = () => {
if (done) resetCIt();
resetCE();
};
const percentIt = () => {
if (actions.length < 1) {
resetCIt();
document.getElementById("holder").textContent = "0";
return;
}
percent(actions, numbers, changedNumbers);
};
const showHistoryIt = () => {
currentShowHistory = true;
showHistory(history);
};
const showMemoryIt = () => {
currentShowHistory = false;
showMemory(memory);
};
const memoryHandlerIt = (Event) => {
memoryHandler(Event, memory, changedNumbers, done);
if (!currentShowHistory) showMemoryIt();
};
(function addingEventListeners() {
document
.getElementsByClassName("equals")[0]
.addEventListener("click", calculateIt, false);
const btnNumbers = document.querySelectorAll(".numbers");
btnNumbers.forEach(function setTheEventForEachNumberButton(button) {
button.addEventListener("click", addNumberIt, false);
});
document.getElementById("delete").addEventListener("click", removerIt, false); // Event for the Delete button
const btnFunctions = document.querySelectorAll(".functionShowAble");
btnFunctions.forEach(function addEventListenerForFunctions(button) {
button.addEventListener("click", addFunctionShowAbleIt, false);
});
document
.getElementsByClassName("ce")[0]
.addEventListener("click", resetCEIt, false);
document
.getElementsByClassName("c")[0]
.addEventListener("click", resetCIt, false);
document
.getElementsByClassName("plus-minus")[0]
.addEventListener("click", togglePositivity, false);
document
.getElementsByClassName("one-divided-x")[0]
.addEventListener("click", oneDividedByNumber, false);
document
.getElementsByClassName("x-squared")[0]
.addEventListener("click", numberSquared, false);
document
.getElementsByClassName("cube-x")[0]
.addEventListener("click", numberCubed, false);
document
.getElementsByClassName("dot")[0]
.addEventListener("click", decimal, false);
document
.getElementsByClassName("squared-x")[0]
.addEventListener("click", root, false);
document
.getElementsByClassName("percent")[0]
.addEventListener("click", percentIt, false);
document
.getElementsByClassName("history-m")[0]
.addEventListener("click", showHistoryIt, false);
document
.getElementsByClassName("memory")[0]
.addEventListener("click", showMemoryIt, false);
const ms = document.querySelectorAll(".main-m");
ms.forEach((m) => {
m.addEventListener("click", memoryHandlerIt, false);
});
})();