File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -73,21 +73,26 @@ btns.forEach((btn) => {
7373 canUserAddDot ( ) ;
7474 }
7575
76- // This is the = fuction
76+
7777 if ( buttonValue === "=" ) {
7878 try {
7979 const replacedArray = data . map ( ( item ) => ( item === "x" ? "*" : item === "÷" ? "/" : item ) ) ;
80- let result = eval ( replacedArray . join ( "" ) ) ;
81- console . log ( eval ( replacedArray . join ( "" ) ) ) ;
82- displayResult ( replacedArray , result ) ;
83- zeroDivedByZero ( screen , result )
84- divideByZero ( screen , result ) ;
85- data = [ ] ;
86- data . push ( result )
80+ // Check if the expression involves 0/0
81+ if ( hasZeroDividedByZero ( replacedArray ) ) {
82+ screen . innerText = "Invalid format used. You cannot divide by zero" ;
83+ } else {
84+ let result = eval ( replacedArray . join ( "" ) ) ;
85+ console . log ( result ) ;
86+ displayResult ( replacedArray , result ) ;
87+ divideByZero ( screen , result ) ;
88+ data = [ ] ;
89+ data . push ( result ) ;
90+ }
8791 } catch ( e ) {
8892 screen . innerText = `${ e . name } press AC` ;
8993 }
9094 }
95+
9196
9297 function divideByZero ( display , outcome ) {
9398 outcome === Infinity
You can’t perform that action at this time.
0 commit comments