From a42622c1dbabb9d869ec9ed80720e67a45d6302a Mon Sep 17 00:00:00 2001 From: josueJURE Date: Sat, 23 Dec 2023 16:41:57 +0000 Subject: [PATCH 1/3] create history variable --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index e51b181..075e9be 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const operators = document.querySelectorAll("[data-operator]"); const operatorRegex = /[\/*\-+]/; const ZERO = 0; const ZERO_DOT = '0.'; +const history = []; let data = []; From 5fe41ae69fbe33f96ed8967c9ffb05acb8c7c961 Mon Sep 17 00:00:00 2001 From: josueJURE Date: Sat, 23 Dec 2023 17:51:54 +0000 Subject: [PATCH 2/3] use splice() to add '=' and variable result to replacedArray --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 075e9be..7667b9e 100644 --- a/index.js +++ b/index.js @@ -182,7 +182,9 @@ function userClicksOnEqualButton(button) { screen.innerText = "0รท0 is an invalid format. Press AC"; } else { let result = eval(replacedArray.join("")); - console.log(result); + replacedArray.splice(replacedArray.length, 0, "=", result); + console.log(replacedArray.join("")); + displayResult(replacedArray, result); screen.innerText = !Number.isFinite(result) ? "You cannot divide by zero. Press AC" : result; // divideByZero(screen, result); From 16d5f3fcf519082817ed99d71503cb201e2e07a2 Mon Sep 17 00:00:00 2001 From: josueJURE Date: Sat, 23 Dec 2023 18:00:15 +0000 Subject: [PATCH 3/3] call join() on replacedArray --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7667b9e..0738fdc 100644 --- a/index.js +++ b/index.js @@ -183,7 +183,8 @@ function userClicksOnEqualButton(button) { } else { let result = eval(replacedArray.join("")); replacedArray.splice(replacedArray.length, 0, "=", result); - console.log(replacedArray.join("")); + history.push(replacedArray.join("")) + console.log(history); displayResult(replacedArray, result); screen.innerText = !Number.isFinite(result) ? "You cannot divide by zero. Press AC" : result;