我正在使用一個(gè) reactjs 計(jì)算器應(yīng)用程序。它應(yīng)該像一個(gè)簡(jiǎn)單的手持計(jì)算器一樣工作。到目前為止,我已經(jīng)設(shè)法捕獲并顯示第一和第二操作數(shù)的用戶輸入以及要執(zhí)行的操作(+,-,/,*)使用狀態(tài)和setState。當(dāng)我按下“equals”按鈕時(shí),麻煩就來了,它應(yīng)該調(diào)用我稱之為EqualsSign()的函數(shù),以便獲得答案并將其顯示在屏幕上。無(wú)論我輸入什么數(shù)字,我都得到0作為答案。代碼如下:EqualsSign(){ this.A=parseFloat(this.state.operand) console.log("A is ",this.A)// debuging line this.B=parseFloat(this.state.operand2) console.log("B is ", this.B) switch(this.state.operation){ case "+": console.log(this.state.operation) this.setState({answer: (this.A+this.B).toString()}, console.log(this.state.answer)) this.setState({operand: this.state.answer, operand2: '', operation: ''}) break case "-": console.log(this.state.operation) this.setState({answer: this.A+this.B}, console.log(this.state.answer)) this.setState({operand: this.state.answer, operand2: '', operation: ''}) break case "*": console.log(this.state.operation) this.setState({answer: this.A+this.B}, console.log(this.state.answer)) this.setState({operand: this.state.answer, operand2: '', operation: ''}) break case "÷": console.log(this.state.operation) this.setState({answer: this.A+this.B}, console.log(this.state.answer)) this.setState({operand: this.state.answer, operand2: '', operation: ''}) break default: // }}計(jì)算應(yīng)用和控制臺(tái)日志的屏幕截圖,顯示 0 作為 A+B 的輸出(A=15,B=12你能幫忙嗎,我在這里做錯(cuò)了什么?
如何在我的 Reactjs 計(jì)算器應(yīng)用程序上顯示計(jì)算器輸出
墨色風(fēng)雨
2022-08-18 10:45:55