The logic for testing a string agains a regex is only working when the if statement is preceded by a console.log
including matching logic.
I have tried directly using the value returned from this.props, rewriting the code into an if/else if statement, reordering the statements, removing other statements, changing the logic in the console.log.
const operatorRegex = /[+]|[-]|[*]|[/]/g,
equalsRegex = /[=]/g,
numberRegex = /[\d]/g,
decimalRegex = /[.]/g,
currentSumLength = this.props.inputSeq.length,
currInput = e.target.textContent,
firstChar = this.props.inputSeq[0],
prevSum = this.props.prevSum,
prevChar = this.props.lastInput;
if(operatorRegex.test(currInput)) {
if((currentSumLength === 0) && (prevSum === '')) {
alert('Why you starting a sum with an operator?');
}
console.log(operatorRegex.test(prevChar))
if(operatorRegex.test(prevChar)) {
alert('Two in a row');
}
this.props.inputOperator(currInput)
} else if (Other logic) {
Other Code
}
When the user inputs two operators (+,-,/,=) it should alert with the error.