diff --git a/assets/js/app.js b/assets/js/app.js index ac1f53f..ef9d0a3 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1,7 +1,6 @@ const calculatorBtn = document.getElementById("calculatorBtn"); const show = document.getElementById("show"); - // value receive from button let calData = []; const getValue = (value) => { @@ -20,6 +19,18 @@ const getValue = (value) => { return false; } } + // remove extra beside symbol + if ( + calData && + (calData.join("").endsWith("+") || + calData.join("").endsWith("-") || + calData.join("").endsWith("*") || + calData.join("").endsWith("/")) && + (value == "+" || value == "-" || value == "*" || value == "/") + ) { + calData.pop(); + } + calData.push(value); show.value = calData.join(""); }; diff --git a/index.html b/index.html index 059734f..bd0e872 100644 --- a/index.html +++ b/index.html @@ -5,16 +5,21 @@ -