Skip to content

Commit f1c7efc

Browse files
committed
feat(JS): create historyEntries variable and call forEach() on it
1 parent 8e35184 commit f1c7efc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ body {
4747
height: 530px;
4848
width: 400px;
4949
display: flex;
50-
display: flex;
50+
flex-direction: column;
5151
visibility: hidden;
5252
}
5353

index.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const btns = document.querySelectorAll("[data-value]");
2-
const computationHistory = document.querySelector(".computation-history");
2+
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");
@@ -16,11 +16,11 @@ console.log(slidingPart)
1616

1717
historyBtn.addEventListener("click", () => {
1818
slidingPart.classList.toggle("slide")
19-
computationHistory.classList.toggle("visility")
19+
historyElement.classList.toggle("visility")
2020
})
2121

2222

23-
console.log(computationHistory )
23+
2424

2525

2626

@@ -192,6 +192,8 @@ function userClicksOnEqualButton(button) {
192192
const replacedArray = data.map((item) =>
193193
item === "x" ? "*" : item === "÷" ? "/" : item
194194
);
195+
196+
// console.log(historyEntries)
195197
// Check if the expression involves 0/0
196198
// if (areYouDivindingByZero(replacedArray)) {
197199
// screen.innerText = "You cannot divide by zero. Press AC";
@@ -201,8 +203,23 @@ function userClicksOnEqualButton(button) {
201203
screen.innerText = "0÷0 is an invalid format. Press AC";
202204
} else {
203205
let result = eval(replacedArray.join(""));
206+
let historyEntries = [...replacedArray, "=", result];
207+
// let computationHistory = replacedArray.slice();
208+
204209
replacedArray.splice(replacedArray.length, 0, "=", result);
205-
history.push(replacedArray.join(""))
210+
// history.push(replacedArray.join(""));
211+
212+
console.log(historyEntries)
213+
historyEntries.forEach(entry => {
214+
history.push(entry);
215+
console.log(history.join(" "))
216+
historyElement.innerHTML += history
217+
})
218+
219+
historyElement.innerHTML += history.join(" ")
220+
221+
222+
206223
console.log(history);
207224

208225

@@ -211,9 +228,10 @@ function userClicksOnEqualButton(button) {
211228
// divideByZero(screen, result);
212229
data = [];
213230
data.push(result);
214-
computationHistory.innerHTML += `<li>${history}</li>`
231+
215232
}
216233
} catch (e) {
234+
debugger
217235
screen.innerText = `${e.name} press AC`;
218236
}
219237
}

0 commit comments

Comments
 (0)