Jelajahi Sumber

autofocus result input, comment typo, replace all ' ' with 0

Bernadette Elena Hammerle 3 tahun lalu
induk
melakukan
cea221843c
1 mengubah file dengan 3 tambahan dan 3 penghapusan
  1. 3 3
      src/Addition.js

+ 3 - 3
src/Addition.js

@@ -12,7 +12,7 @@ let noOfDigits = 0;
 function Addition() {
   const [input, setInput] = useState(""); // initial user input like 34+56.7
   const [realResult, setRealResult] = useState(0); // real result of calculation
-  const [carryArr, setCarryArr] = useState([]); // array of carries [1","0"]
+  const [carryArr, setCarryArr] = useState([]); // array of carries ["1","0"]
   const [commaIdx, setCommaIdx] = useState(0); // int: comma position
   const [numbers, setNumbers] = useState(0); // array of arrays with input numbers
   const [showAlert, setShowAlert] = useState(false);
@@ -135,7 +135,7 @@ function Addition() {
             onChange={(e) => handleResChange(e, nosLeft)}
             type="text" id="input_result" size="2"
             aria-labelledby="input_result_label" aria-required="true"
-            ref={resInputField}/>
+            ref={resInputField} autoFocus/>
           <br/>
           <label htmlFor="input_carry" id="input_carry_label">
             {carryText}
@@ -215,7 +215,7 @@ function Addition() {
       if (trueNumbers){
         text += resArr[idxNumbers]
         text += " und " + carries[idxCarry-1] + " Übertrag "
-        text = text.replace("&nbsp;", "0")
+        text = text.replace(/&nbsp;/g, "0")
         text += resArr[idxNumbers]===realSum && carries[idxCarry-1]===realCarry ? "(Richtig)" : "(Falsch)";
 
         stepsGridCopy.push({step: text});