File tree Expand file tree Collapse file tree 1 file changed +25
-13
lines changed
Expand file tree Collapse file tree 1 file changed +25
-13
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments