Skip to content

Commit 4a95ab5

Browse files
committed
feat(JS) removesDecimalPointIfPrecededByAnOperator(button)
1 parent 3d908a8 commit 4a95ab5

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

index.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ btns.forEach((btn) => {
2020

2121
userClicksOnEqualButton(buttonValue);
2222

23+
handlingZeroFollowedByAdecimal(buttonValue);
2324

24-
handlingZeroFollowedByAdecimal(buttonValue)
25+
removesDecimalPointIfPrecededByAnOperator(buttonValue)
26+
27+
28+
29+
30+
2531

2632

2733

@@ -30,19 +36,9 @@ btns.forEach((btn) => {
3036
data.push(screen.innerText);
3137
screen.innerText = data.join("");
3238
}
33-
if (/[\/*\-+]/.test(buttonValue)) {
34-
if (data.slice(-1)[0] === ".") {
35-
data.pop();
36-
}
37-
buttonValue === "*"
38-
? (buttonValue = "x")
39-
: buttonValue === "/"
40-
? (buttonValue = "÷")
41-
: buttonValue;
4239

43-
data.push(buttonValue);
44-
screen.innerText = data.join("");
45-
}
40+
41+
4642

4743

4844

@@ -222,3 +218,19 @@ function handlingZeroFollowedByAdecimal(button) {
222218
screen.innerText += buttonValue;
223219
}
224220
}
221+
222+
function removesDecimalPointIfPrecededByAnOperator(button) {
223+
if (/[\/*\-+]/.test(button)) {
224+
if (data.slice(-1)[0] === ".") {
225+
data.pop();
226+
}
227+
button === "*"
228+
? (button = "x")
229+
: button === "/"
230+
? (button = "÷")
231+
: button;
232+
233+
data.push(button);
234+
screen.innerText = data.join("");
235+
}
236+
}

0 commit comments

Comments
 (0)