Skip to content

Commit 4e76662

Browse files
committed
feat (JS) modify toggleSign() so that user can make operations on two negative values
1 parent 61b2a1c commit 4e76662

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ const operators = document.querySelectorAll("[data-operator]");
44

55
let data = [];
66

7+
8+
79
btns.forEach((btn) => {
810
btn.addEventListener("click", function (e) {
911
let buttonValue = e.target.dataset.value;
10-
1112
// if (buttonValue === "(") {
1213
// let isOpenParenthesis = true;
1314
// for (let i = data.length - 1; i >= 0; i--) {
@@ -77,7 +78,9 @@ btns.forEach((btn) => {
7778

7879
if (buttonValue === "=") {
7980
try {
81+
console.log(data)
8082
let result = eval(data.join(""));
83+
console.log(eval(data.join("")))
8184
displayResult(data, result);
8285
divideByZero(screen, result);
8386
} catch (e) {
@@ -133,7 +136,7 @@ function canUserAddDot() {
133136
}
134137
data.push(".");
135138
}
136-
screen.innerText = data.join("");
139+
screen.innerText = data.join(" ");
137140
}
138141

139142
function deleteEverythingFromScreen() {
@@ -144,11 +147,13 @@ function deleteEverythingFromScreen() {
144147

145148
function toggleSign() {
146149
let currentValue = data[data.length - 1];
150+
console.log(currentValue)
147151
if (currentValue === undefined) return;
148152
let toggledValue = -currentValue;
149-
screen.innerText = toggledValue; // Update the screen
153+
// screen.innerText = toggledValue; // Update the screen
150154
// Update the value in the data array
151155
data[data.length - 1] = toggledValue;
156+
screen.innerText = data.join("");
152157
console.log(data);
153158
}
154159

0 commit comments

Comments
 (0)