Hi FreecodeCampers,
If you click AC in my calculator it displays “0” in the display element and then once you start typing again the display element will show what you type. However, it does not pass this test so I must have written the code wrong. Below is a key part of the code and the link to the code pen. Is there something wrong with my approach to use innerText? Any suggestions on why AC is not functioning as intended,
https://codepen.io/Egglearn/pen/mdJvqxm?editors=1111
handleClick(event) {
let eventtext = event.target.innerText;
this.setState((prevState) => ({
answerbackup: prevState.answerbackup.concat(eventtext),
answer: prevState.answerbackup.concat(eventtext)
//the reason I have answerback up is because after you press AC it sets answer to:"0",this was creating problems because then when prevState is concat with the new text 0 stays at the beginning. answerbackup helped me get around this because it has an initial state of "" so when it is concat with the new event it replaces the 0 and the text in the display element looks as it should.
}));
}
clear() {
this.setState({
result: [],
answer: "0",
addition: "",
answerbackup: ""
});
}