Skip to content

Commit f02b5e8

Browse files
committed
feat(JS): remove all console.log()
1 parent 8786e90 commit f02b5e8

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

index.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@ const historyElement = document.querySelector(".computation-history");
33
let screen = document.querySelector("[data-screen]");
44
const historyBtn = document.querySelector(".history-btn");
55
const slidingPart = document.querySelector(".sliding-part");
6-
const computationHistoryParent = document.querySelector(".computation-history-parent")
6+
const computationHistoryParent = document.querySelector(
7+
".computation-history-parent"
8+
);
79
const operators = document.querySelectorAll("[data-operator]");
810
const clearHistoryBtn = document.querySelector(".clear-history-btn");
911

10-
11-
console.log(clearHistoryBtn);
12-
13-
clearHistoryBtn.addEventListener("click", () => { historyElement.innerHTML = ""})
14-
15-
12+
clearHistoryBtn.addEventListener("click", () => {
13+
historyElement.innerHTML = "";
14+
});
1615

1716
const operatorRegex = /[\/*\-+]/;
1817
const ZERO = 0;
19-
const ZERO_DOT = '0.';
18+
const ZERO_DOT = "0.";
2019
const HISTORY_LIMIT = 10;
2120
const history = [];
2221

23-
console.log(slidingPart)
24-
25-
2622
historyBtn.addEventListener("click", () => {
27-
slidingPart.classList.toggle("slide")
23+
slidingPart.classList.toggle("slide");
2824
computationHistoryParent.classList.toggle("visility");
29-
})
30-
31-
32-
33-
34-
35-
25+
});
3626

3727
let data = [];
3828

@@ -61,10 +51,6 @@ btns.forEach((btn) => {
6151
deteLastEntry(buttonValue);
6252

6353
convertToPercentage(buttonValue);
64-
65-
66-
67-
6854
});
6955
});
7056
// forEach ends & functions creations begins
@@ -75,10 +61,8 @@ function convertToPercentage(button) {
7561
}
7662

7763
clearHistoryBtn.addEventListener("click", () => {
78-
79-
historyElement.innerHTML = ""
80-
console.log(historyElement.childElementCount)
81-
})
64+
historyElement.innerHTML = "";
65+
});
8266

8367
function deteLastEntry(button) {
8468
if (button === "DE") {
@@ -95,7 +79,6 @@ function canUserAddDot(button) {
9579
if (button === ".") {
9680
var dotAllowed = true;
9781
for (var i = data.length - 1; i >= ZERO; i--) {
98-
console.log("data > " + data[i]);
9982
if (data[i] === ".") {
10083
dotAllowed = false;
10184
break;
@@ -129,7 +112,6 @@ function toggleSign(button) {
129112
let reversedExpression = currentExpression.split("").join("");
130113
let match = reversedExpression.match(/(\d+(\.\d+)?)|(\D+)/); // Match a number or non-digit
131114

132-
133115
if (match) {
134116
let start = currentExpression.length - match[ZERO].length;
135117
let end = currentExpression.length;
@@ -206,15 +188,18 @@ function userClicksOnEqualButton(button) {
206188
if (button === "=") {
207189
try {
208190
const replacedArray = data.map((item) =>
209-
item === "x" ? "*" : item === "÷" ? "/" : item);
191+
item === "x" ? "*" : item === "÷" ? "/" : item
192+
);
210193
if (areYouDividingdZeroByZero(replacedArray)) {
211194
screen.innerText = "0÷0 is an invalid format. Press AC";
212195
} else {
213196
let result = eval(replacedArray.join(""));
214197
let historyEntries = [[...replacedArray, "=", result]];
215198
replacedArray.splice(replacedArray.length, 0, "=", result);
216199
displayResult(replacedArray, result);
217-
screen.innerText = !Number.isFinite(result) ? "You cannot divide by zero. Press AC" : result;
200+
screen.innerText = !Number.isFinite(result)
201+
? "You cannot divide by zero. Press AC"
202+
: result;
218203
data = [];
219204
data.push(result);
220205
createHistoryList(historyEntries, historyElement, history);
@@ -253,16 +238,13 @@ function displayResult(array, outcome) {
253238
array.push(outcome);
254239
}
255240

256-
257241
function createHistoryList(array, element, history) {
258-
array.forEach((entry, index) => {
242+
array.forEach((entry) => {
259243
history.push(entry);
260-
element.innerHTML += `<li> ${entry.join(" ")}</li>`
261-
if(element.childElementCount > HISTORY_LIMIT) {
244+
element.innerHTML += `<li> ${entry.join(" ")}</li>`;
245+
if (element.childElementCount > HISTORY_LIMIT) {
262246
element.firstElementChild.remove();
263247
}
264-
265-
266248
});
267249
}
268250
clearHistoryBtn.addEventListener("click", () => {

0 commit comments

Comments
 (0)