@@ -10,6 +10,7 @@ document.getElementById("answer").readOnly = true; //set this attribute in Html
10
10
let screen = document . getElementById ( "answer" ) ;
11
11
buttons = document . querySelectorAll ( "button" ) ;
12
12
let screenValue = "" ;
13
+ let maxItems = 6 ;
13
14
for ( item of buttons ) {
14
15
item . addEventListener ( "click" , ( e ) => {
15
16
buttonText = e . target . innerText ;
@@ -102,6 +103,12 @@ window.onerror = function () {
102
103
window . onBracketMultiplication = function ( ) {
103
104
screenValue = addStr ( screen . value , screen . value . indexOf ( "(" ) , "*" ) ;
104
105
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 ) ) ;
105
112
} ;
106
113
107
114
function addStr ( str , index , stringToAdd ) {
@@ -120,6 +127,12 @@ function checkForBracketMulti() {
120
127
return ;
121
128
} else {
122
129
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 ) ) ;
123
136
}
124
137
flag = 1 ;
125
138
}
0 commit comments