Browse Source

fix result position

Bernadette Elena Hammerle 3 years ago
parent
commit
9fd288dcf3
3 changed files with 12 additions and 8 deletions
  1. 3 3
      src/Addition.js
  2. 1 4
      src/App.css
  3. 8 1
      src/Subtraction.js

+ 3 - 3
src/Addition.js

@@ -403,9 +403,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){

+ 1 - 4
src/App.css

@@ -21,6 +21,7 @@ main ul li a{
 
 td{
   white-space: pre-wrap;
+  padding-left: 40px;
 }
 
 hr{
@@ -38,10 +39,6 @@ hr{
   padding: 0px 7px;
 }
 
-#overview table{
-  margin: 0 auto;
-}
-
 #overview p{
   margin: 0.2em 1em;
 }

+ 8 - 1
src/Subtraction.js

@@ -457,7 +457,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 = "";