@@ -4,8 +4,6 @@ const operators = document.querySelectorAll("[data-operator]");
44
55let data = [ ] ;
66
7-
8-
97btns . forEach ( ( btn ) => {
108 btn . addEventListener ( "click" , function ( e ) {
119 let buttonValue = e . target . dataset . value ;
@@ -24,7 +22,6 @@ btns.forEach((btn) => {
2422 let isOpenparenthesis = true ;
2523 for ( let i = data . length - 1 ; i >= 0 ; i -- ) {
2624 if ( / ^ \d $ / . test ( data [ i ] ) ) {
27- console . log ( "last element in array " + data [ i ] ) ;
2825 isOpenparenthesis = false ;
2926 break ;
3027 }
@@ -51,8 +48,6 @@ btns.forEach((btn) => {
5148 deleteEverythingFromScreen ( ) ;
5249 }
5350
54-
55-
5651 if ( Number ( buttonValue ) === 0 && screen . innerText . startsWith ( "0." ) ) {
5752 screen . innerText += buttonValue ;
5853 }
@@ -65,6 +60,11 @@ btns.forEach((btn) => {
6560 if ( data . slice ( - 1 ) [ 0 ] === "." ) {
6661 data . pop ( ) ;
6762 }
63+ if ( buttonValue === "*" ) {
64+ buttonValue = "x" ;
65+ } else if ( buttonValue === "/" ) {
66+ buttonValue = "÷" ;
67+ }
6868 data . push ( buttonValue ) ;
6969 screen . innerText = data . join ( "" ) ;
7070 }
@@ -78,10 +78,11 @@ btns.forEach((btn) => {
7878
7979 if ( buttonValue === "=" ) {
8080 try {
81- console . log ( data )
82- let result = eval ( data . join ( "" ) ) ;
83- console . log ( eval ( data . join ( "" ) ) )
84- displayResult ( data , result ) ;
81+ const replacedArray = data . map ( ( item ) => ( item === "x" ? "*" : item === "÷" ? "/" : item ) ) ;
82+ console . log ( data ) ;
83+ let result = eval ( replacedArray . join ( "" ) ) ;
84+ console . log ( eval ( replacedArray . join ( "" ) ) ) ;
85+ displayResult ( replacedArray , result ) ;
8586 divideByZero ( screen , result ) ;
8687 } catch ( e ) {
8788 screen . innerText = `${ e . name } press AC` ;
@@ -147,14 +148,10 @@ function deleteEverythingFromScreen() {
147148
148149function toggleSign ( ) {
149150 let currentValue = data [ data . length - 1 ] ;
150- console . log ( currentValue )
151151 if ( currentValue === undefined ) return ;
152152 let toggledValue = - currentValue ;
153153 // screen.innerText = toggledValue; // Update the screen
154154 // Update the value in the data array
155155 data [ data . length - 1 ] = toggledValue ;
156156 screen . innerText = data . join ( "" ) ;
157- console . log ( data ) ;
158157}
159-
160-
0 commit comments