2
I’m building a calculator (https://jsfiddle.net/rwt3am1L/). The result of the calculation appears on the screen when I click the equals key, after that it gives a "reset", however, this "reset" is happening before the result comes out on the screen. I have an idea of what’s going on, but I don’t know how to fix it.
const reset = (res, calc) => {
const cleanRes = res.textContent = "";
const cleanCalc = calc.length = ""
return {
cleanCalc;
}
};
const showResult = (res, calc) => {
res.textContent = eval(calc.join(""));
const { cleanCalc } = reset(res, calc);
};
I just wanted to call the function "cleanCalc" inside "reset", but it seems that every function is executed, because the response box is also cleaned through the variable "cleanRes".
If I do it this way, it works, but not the other way:
const reset = (res, calc) => {
const cleanRes = res.textContent = "";
const cleanCalc = calc.length = ""
};
const showResult = (res, calc) => {
res.textContent = eval(calc.join(""));
calc.length = "";
};
I just wouldn’t want to repeat code. It’s possible to do what I’m trying to?
Thanks for your attention!
I think your question needs more details. Try [Edit] to add more information.
– Luiz Felipe
I tried to explain in another way, I think now is better to understand.
– Thales Maia