Not passing test 11 even though i get 5.5.5 to convert to 5.55 and 5..5 to 5.5 in javascript calculator

const handleInput = (e) => {
    let val = e.target.textContent;

    setCalc((calc.input = calc.input.replace(/\.+/g, ".")));

    setCalc((calc.input = calc.input.replace(
         /(\d+)(\.)(\d+)(\.)(\d+)/,
        (p1, p2, p3, p4, p5, p6) => {
          let arr = [p2, p3, p4, p6];
          return arr.join("");
        }
      ))
    );

    console.log(calc.input);

    if (calc.input === "0") {
      setCalc((calc.input = ""));
    } else if (calc.input.match(/(^0)\1{2,}/)) {
      setCalc(calc.input.replace(/(^0)\1{2,}/g, "0"));
    }
    setCalc({ input: calc.input + val });
  };

I use the replace function with regex to convert the user input into the correct format before the calculation happens.
I’m getting the right results so i don’t understand why the test is not passing.

I can type 5.5.5 into the calculator, which isn’t a valid number – that’s why the test is failing. Even if you change it during the calculation, you’re still allowing invalid input

1 Like

Thank you. Back to the drawing board then