I've been practicing and honing my Javascript skills by working on a calculator code that initially had lots of repetitive lines. I managed to simplify it, but I am aware that using the eval() method is not generally recommended.
let current = 0;
function calculate(method){
const result = `${current} ${method} ${userInput.value}`;
current = eval(result);
outputResult(current, result);
}
addBtn.addEventListener('click', ()=> calculate('+'));
subtractBtn.addEventListener('click', ()=> calculate('-'));
multiplyBtn.addEventListener('click', ()=> calculate('*'));
divideBtn.addEventListener('click', ()=> calculate('/'));