JavaScript Calculator - test 7

May somebody please point out, why the 7th test isn´t passing while everything seems to work porperly?

Kind Regards and thank you!

At any time, pressing the clear button clears the input and output values, and returns the calculator to its initialized state; 0 should be shown in the element with the id of “display”

Element with with id=“display” should show 0 : expected ‘’ to equal ‘0’

Are you setting it to 0 when you clear?

I did. At first my code looked like this

if (value === "AC") {
      this.setState({
        firstLine: "0",
        secondLine: "0"
      });
    } else
      if (value === "=") {
        if (this.state.firstLine !== "0") {
          const operator = this.state.secondLine.match(/^[-+*/]/);
          const two = this.state.secondLine.slice(
            1,
            this.state.secondLine.length
          );

          const result = eval(this.state.firstLine + operator + two);
          this.setState({
            firstLine: result,
            secondLine: "0"
          });
        } else {
          const result = eval(this.state.secondLine);
          this.setState({
            firstLine: result,
            secondLine: "0"
          });
        }
      }

I didn´t pass the 7th test so i commented the “firstLine” out at first.

After commenting the whole conditional statements out I wrote

clearInput = () => {
    this.setState({
      // firstLine: "0",
      secondLine: "0"
    });
  };

But that didn´t work either.

You have the Display component twice. Remove it from the Calculator component.

Thank you very much!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.