React Calculator (using reducer hook), issue with .match() and operation

I have made a basic calculator in React using the reducer hook, however, there are two issues arising: I have the state as {prevOperand,currentOperand, operation}

  1. In the case where two operators are clicked consecutively, I want to check if the last character in the string in the currentOperand contains any of the arithmetic operators so that I can return the same state back (preventing the second selected operator from entering). However, the .match method doesn’t seem to be working, and the return statement in the ‘if’ loop isn’t getting executed. What might be the problem here?

  2. I have used a function for evaluating the numbers entered in currentOperand, which returns the value of the variable “result”, which is equated to the currentOperand.Afterwards, when I press any operation (or) the DEL (DELETE) button, I am getting an error. How to resolve this???

Git Hub Link

add the images of the part of the code that needs to be scrutinized:

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