@@ -10,6 +10,7 @@ document.getElementById("answer").readOnly = true; //set this attribute in Html
1010let screen = document . getElementById ( "answer" ) ;
1111buttons = document . querySelectorAll ( "button" ) ;
1212let screenValue = "" ;
13+ let maxItems = 6 ;
1314for ( item of buttons ) {
1415 item . addEventListener ( "click" , ( e ) => {
1516 buttonText = e . target . innerText ;
@@ -102,6 +103,12 @@ window.onerror = function () {
102103window . onBracketMultiplication = function ( ) {
103104 screenValue = addStr ( screen . value , screen . value . indexOf ( "(" ) , "*" ) ;
104105 screen . value = eval ( screenValue ) ;
106+ let calcHistory = JSON . parse ( localStorage . getItem ( "calcHistory" ) ) || [ ] ;
107+ if ( calcHistory . length >= maxItems ) {
108+ calcHistory . shift ( ) ;
109+ }
110+ calcHistory . push ( { screenValue, result : screen . value } ) ;
111+ localStorage . setItem ( "calcHistory" , JSON . stringify ( calcHistory ) ) ;
105112} ;
106113
107114function addStr ( str , index , stringToAdd ) {
@@ -120,6 +127,12 @@ function checkForBracketMulti() {
120127 return ;
121128 } else {
122129 screen . value = eval ( screenValue ) ;
130+ let calcHistory = JSON . parse ( localStorage . getItem ( "calcHistory" ) ) || [ ] ;
131+ if ( calcHistory . length >= maxItems ) {
132+ calcHistory . shift ( ) ;
133+ }
134+ calcHistory . push ( { screenValue, result : screen . value } ) ;
135+ localStorage . setItem ( "calcHistory" , JSON . stringify ( calcHistory ) ) ;
123136 }
124137 flag = 1 ;
125138}
0 commit comments