FreeCodeCamp Javascript calculator test suite | I don't know why I can't pass this test

So I'm doing that FCC javascript calculator test, and I'm just stuck.

my code seems to be working but test suite says I'm not getting half of it so I just wanted to ask if you guys can point me to a write direction.

Also I'm keep getting this msg:

    Uncaught SyntaxError: Invalid left-hand side in assignment.

But I don't know what it's referring to.

const equalStyle = {
  height: 120,
  backgroundColor: "#995ba4",
  bottom:7,
  position:"absolute"
};
const clearStyle = {backgroundColor: "#b83146"};
const equationStyle = {backgroundColor: "#b2b2b2"};
const equation = /[/*+-]/;
const confirmEquation = /[/*+-]$/;
const secondConfirm =/\d[x/+‑*]‑$/;
const negative = /[-]/;
const dotTester = /[.]/;
const prevTester = /^[/*-+]/;
      

class Main extends React.Component{
  constructor(props){
    super(props);
    this.state={
      totalVal:"",
      testVal:"0",
      displayVal:"0",
      prevVal:""
    }
    this.clickedVal = this.clickedVal.bind(this);
    this.calDisplay = this.calDisplay.bind(this);
  }
  
 calDisplay(val){
    if(this.state.displayVal == "0"){
      if(this.state.totalVal == ""){
        this.setState({
        totalVal: val
        })
      }
    } 
    else{
      this.setState({totalVal:this.state.totalVal + val})
    }
  }
  
  
 clickedVal(e){
    let clickVal = e.target.value;
    if (clickVal=="x"){clickVal = clickVal.replace("x", "*")};
   
    if(this.state.totalVal.includes("=")){
      this.setState({
        totalVal:"",
        testVal:"0",
        displayVal:"0"
      })
    }
   
  setTimeout(()=>{
      if(this.state.testVal == "0"&&!isNaN(parseInt(clickVal))){
        this.setState({ displayVal:clickVal, testVal:clickVal}, this.calDisplay(clickVal))
      }
      
      else if (!isNaN(parseInt(clickVal))){
      this.setState({ displayVal: this.state.displayVal + clickVal,testVal:this.state.displayVal + clickVal},this.calDisplay(clickVal))
      }
      /*equation stuff*/
      else if(equation.test(clickVal)){
          if(confirmEquation.test(this.state.totalVal)){
              if(negative.test(clickVal)){
                this.calDisplay(clickVal)
                this.setState({displayVal: clickVal, testVal:"0"})
              }
           
              else if(secondConfirm.test(this.state.totalVal)){
                  this.setState({
                      displayVal: clickVal, testVal:"0", totalVal: this.state.totalVal.slice(0, this.state.totalVal.length-2)
                    });
              setTimeout(()=>this.calDisplay(clickVal))
              }
            
              else{
                  this.setState({
                      displayVal: clickVal, testVal:"0", totalVal: this.state.totalVal.slice(0, this.state.totalVal.length-1)
                  });
              setTimeout(()=>this.calDisplay(clickVal))
              }
          }  
      
        else if (typeof(this.state.prevVal) == "number"  && this.state.displayVal =="0"){
            this.setState({displayVal:clickVal, testVal:"0"})
            this.calDisplay(this.state.prevVal+clickVal)
        }
        
        else{
            this.setState({displayVal:clickVal, testVal:"0"})
            this.calDisplay(clickVal);
        }
    }
      
      else if(clickVal == "."){
        if(confirmEquation.test(this.state.totalVal)){
          this.calDisplay("0.")
          this.setState({ displayVal: "0.", testVal: "0"})
      }
      else if (dotTester.test(this.state.displayVal)){
          this.setState({displayVal: this.state.displayVal ,testVal:this.state.displayVal})
      }
      else{
          this.calDisplay(clickVal);
          this.setState({displayVal: this.state.displayVal + clickVal,testVal:this.state.displayVal + clickVal})
      }
    }
      
      else if (clickVal == "="){
         
        let result = Math.round(1000000000000 * eval(this.state.totalVal)) / 1000000000000;
        this.setState({
          displayVal: result, testVal:"0", prevVal:result
        })
        this.calDisplay("="+result)
      }
      
      else if (clickVal == "AC"){
        this.setState({
          totalVal:"",
          testVal:"0",
          displayVal:"0",
          prevVal:""
      })
    }
   })    
  }
  
  render(){

    return(
      <div className = "calculatorBody" >
        <OutputDisplay formula = {this.state.totalVal}/>
        <InputDisplay currentValue = {this.state.displayVal} />
        <Buttons onClick = {this.clickedVal}/>
      </div>
    )
  }
}

https://codepen.io/arthur-lee945/pen/NWaebeV?editors=0111

This is my codepen for it.


Solution 1:

The error occurs when 'this.state.totalVal' is "5-2=3/2" at below codes(117 line).

let result = Math.round(1000000000000 * eval(this.state.totalVal)) / 1000000000000;

And you can check values of this variable by setting a breakpoint at 117 line in the source tab of your browser devtools.