11const btns = document . querySelectorAll ( "[data-value]" ) ;
2- const computationHistory = document . querySelector ( ".computation-history" ) ;
2+ const historyElement = document . querySelector ( ".computation-history" ) ;
33let screen = document . querySelector ( "[data-screen]" ) ;
44const historyBtn = document . querySelector ( ".history-btn" ) ;
55const slidingPart = document . querySelector ( ".sliding-part" ) ;
@@ -16,11 +16,11 @@ console.log(slidingPart)
1616
1717historyBtn . addEventListener ( "click" , ( ) => {
1818 slidingPart . classList . toggle ( "slide" )
19- computationHistory . classList . toggle ( "visility" )
19+ historyElement . classList . toggle ( "visility" )
2020} )
2121
2222
23- console . log ( computationHistory )
23+
2424
2525
2626
@@ -192,6 +192,8 @@ function userClicksOnEqualButton(button) {
192192 const replacedArray = data . map ( ( item ) =>
193193 item === "x" ? "*" : item === "÷" ? "/" : item
194194 ) ;
195+
196+ // console.log(historyEntries)
195197 // Check if the expression involves 0/0
196198 // if (areYouDivindingByZero(replacedArray)) {
197199 // screen.innerText = "You cannot divide by zero. Press AC";
@@ -201,8 +203,23 @@ function userClicksOnEqualButton(button) {
201203 screen . innerText = "0÷0 is an invalid format. Press AC" ;
202204 } else {
203205 let result = eval ( replacedArray . join ( "" ) ) ;
206+ let historyEntries = [ ...replacedArray , "=" , result ] ;
207+ // let computationHistory = replacedArray.slice();
208+
204209 replacedArray . splice ( replacedArray . length , 0 , "=" , result ) ;
205- history . push ( replacedArray . join ( "" ) )
210+ // history.push(replacedArray.join(""));
211+
212+ console . log ( historyEntries )
213+ historyEntries . forEach ( entry => {
214+ history . push ( entry ) ;
215+ console . log ( history . join ( " " ) )
216+ historyElement . innerHTML += history
217+ } )
218+
219+ historyElement . innerHTML += history . join ( " " )
220+
221+
222+
206223 console . log ( history ) ;
207224
208225
@@ -211,9 +228,10 @@ function userClicksOnEqualButton(button) {
211228 // divideByZero(screen, result);
212229 data = [ ] ;
213230 data . push ( result ) ;
214- computationHistory . innerHTML += `<li> ${ history } </li>`
231+
215232 }
216233 } catch ( e ) {
234+ debugger
217235 screen . innerText = `${ e . name } press AC` ;
218236 }
219237 }
0 commit comments