Browse Source

fix result position

Bernadette Elena Hammerle 3 years ago
parent
commit
f5c50b513b
2 changed files with 11 additions and 4 deletions
  1. 3 3
      src/Addition.js
  2. 8 1
      src/Subtraction.js

+ 3 - 3
src/Addition.js

@@ -404,9 +404,9 @@ function Addition() {
 
   const finishCalculation = () => {
     document.getElementById("idmtResultSteps").innerHTML = "";
-    let resCalc = resArr.filter(n => n !== " ").join("");
-    setResultsGrid([{number: resCalc}]);
-    resCalc = parseFloat(resCalc);
+    let resCalc = resArr.join("");
+    setResultsGrid([{number: resCalc.replace(/ /g, " ")}]);
+    resCalc = parseFloat(resCalc.replace(/ /g, ""));
 
     let message = "";
     if(resCalc === realResult){

+ 8 - 1
src/Subtraction.js

@@ -458,7 +458,14 @@ function Subtraction() {
     if(resCalc.startsWith(".")){
       resCalc = "0" + resCalc;
     }
-    setResultsGrid([{number: resCalc}]);
+
+    let maxLen = Math.max(...numbers.map(x => x.length));
+    let resStr = resCalc;
+    while(maxLen > resStr.length){
+      resStr = " " + resStr;
+    }
+
+    setResultsGrid([{number: resStr}]);
     resCalc = parseFloat(resCalc);
 
     let message = "";