text: import React, { useState } from "react";
  import "./App.css";
  
  function App() {
    const [calc, setCalc] = useState("");
    const [result, setResult] = useState("");
  
    const ops = ["/", "*", "-", "+", "."];
  
    const updateCalc = (e) => {
      if (
        (ops.includes(e) && calc === "") ||
        (ops.includes(e) && ops.includes(calc.slice(-1)))
      ) {
        return;
      }
      setCalc(calc + e);
  
      if (!ops.includes(e)) {
        setResult(eval(calc + e).toString());
      }
    };
  
    const createDigits = () => {
      const digits = [];
      for (let i = 1; i < 10; i++) {
        digits.push(
          <button key={i} onClick={() => updateCalc(i.toString())}>
            {i}
          </button>
        );
      }
      return digits;
    };
  
    const calculate = () => {
      setCalc(eval(calc).toString());
    };
  
    const deleteLast = () => {
      if (calc == "") {
        return;
      }
  
      const e = calc.slice(0, -1);
      setCalc(e);
    };
  
    return (
      <div className="App">
        <div className="Calculator">
          <div className="display">
            {result ? <span>({result})</span> : ""}&nbsp;
            {calc || "0"}
          </div>
          <div className="Operators">
            <button onClick={() => updateCalc("/")}>/</button>
            <button onClick={() => updateCalc("*")}>*</button>
            <button onClick={() => updateCalc("+")}>+</button>
            <button onClick={() => updateCalc("-")}>-</button>
  
            <button onClick={deleteLast}>DEL</button>
          </div>
          <div className="Digits">
            {createDigits()}
            <button onClick={() => updateCalc("0")}>0</button>
            <button onClick={() => updateCalc(".")}>.</button>
            <button onClick={calculate}>=</button>
          </div>
        </div>
      </div>
    );
  }
  
  export default App;
  