import React from 'react'; import './Calculator.css'; export default class Calculator extends React.Component { constructor(props) { super(props); this.state = { a: "", b: "", operator: "ADD" } } calcResult({a, operator, b}) { a = parseFloat(a); b = parseFloat(b); if(isNaN(a) || isNaN(b) || !operator) { return ""; } switch(operator) { case "ADD": return a + b; case "SUBTRACT": return a - b; case "MULTIPLY": return a * b; case "DIVIDE": return a / b; } return ""; } render() { return

This interviewer requested that I make a component that allowed a user to input two numbers and select an operator and get a result.

this.setState({a: e.target.value})} /> this.setState({b: e.target.value})} /> = {this.calcResult(this.state)}
; } }