Please help me correct the logic in this Calculator code I am stuck

Here is the code, I have written comments here to explain what logic I want. I need to pass test no. 11 and 13 in JavaScript Calculator and here is link to full code Calculator Codepen

 Calculate(e) {
    const changeState = () => {
      this.setState({
        calcString: (this.state.calcString += e.target.innerHTML),
        display: this.state.calcString
      });
    };

    if (e.target.id == "decimal") {
     // when decimalCounter is <=1 that data is allowed to be entered in this.state.calcString
      if(/[+*\\-]/g.test(this.state.calcString)){
        //whenever an operator is found decimal should be allowed to be entered
        decimalCounter=0;
        console.log("operators found")
        } if(/\d+\.\d+/g.test(this.state.calcString)){
          //whenever something of type 5.5 is found no more decimal should be allowed until next oprator is found
          decimalCounter++;
          console.log("d.d pattern found")
        }else{
          //when simple digits like 5 are entered decimal should be allowed once until something like 5.5 is entered
        decimalCounter++;
          console.log("in decimal code but no operators here")
      }
      
    } else {
      //when other buttons are pressed except decimal,they should be allowed to be entered by setting  decimalCounter = 0
      decimalCounter = 0;
      console.log("hey")
    }

    if (e.target.id == "clear") {
      this.setState({
        display: "0",
        calcString: ""
      });
    }

    if (e.target.id == "equals" && this.state.calcString !== "") {
      this.setState({
        calcString: eval(this.state.calcString),
        display: eval(this.state.calcString)
      });
    }

    if (
      this.state.calcString == "" &&
      e.target.id !== "clear" &&
      e.target.id !== "equals" &&
      e.target.id !== "zero"
    ) {
      changeState();
    } else if (
      this.state.calcString !== "" &&
      e.target.id !== "clear" &&
      e.target.id !== "equals" &&
      decimalCounter <= 1
    ) {
      changeState();
    }
  }

The problem with your code is that tester can’t get past #7, and not necessarily that it fails on 11 an 13, this is because you have not accounted for properly resetting the keysPressed variable after an evaluation, so it hangs up in trying to evaluate slice() on a number, which you can’t do, basically you can do this to trace the source of your error after an evaluation…

    if (e.target.id == "equals" && this.state.calcString !== "") {
      this.setState({
        calcString: eval(this.state.calcString),
        display: eval(this.state.calcString)
      },()=>console.log(typeof this.state.calcString));
    }

The setState callback shows the type of the value of the state after evaluation, which is a number, and since right at the top of Calculate() you set keysPressed =this.state.calcString; , it takes on that value of that number, and as I explained, the tests (or any other manual calcs after eval) get hangup due to a TypeError on trying to slice a number, a simple hack would be to test for the typeof this.state.calcString before setting keysPressed right at the top of Calculate()

Calculate(e) {
   keysPressed = typeof this.state.calcString  === "string" ? this.state.calcString : '';
   let lastTwo= keysPressed.slice(-3);
   .
   .
   .

This will pass the tests till #15, however this is just a hack, you may want to think of better ways to architect your calculator to avoid the problem.

edit: FYI, above I was going off of your latest codepen as of the time of this post and not your code above, making that change above still has 13 fail, but that is a computation issue i believe