Hi, I’m having a lot of trouble figuring out how to prevent a number from having trailing zeros. This is what I have so far in the default case of the switch statement in my handleClick (it’s the first if statement):
default:
if(this.state.evaluation.join("").match(/^00/)){
break;
};
if(isNaN(value) && isNaN(this.state.evaluation[this.state.evaluation.length-1])) {
break;
};
this.setState({evaluation: [...this.state.evaluation, value]}, () => {
this.props.setEvaluation(this.state.evaluation.join(""));
});
break;
}
By using .match(), it causes the input to “freeze up”. In other words, if I begin a calculation with two zeros, not only can I not type more zeros but I simply can’t continue the calculation with hitting the clear button and starting over. What could I be doing wrong here?
Here’s the whole project on codepen: https://codepen.io/Dusch4593/pen/RwbgGer