I'm practicing Javascript and started out with a calculator-code with lots of repetition. I simplified it quite a bit, but I know the eval()-method isn't... hehe... "recommended".
let currentResult = 0;
function calculate(method){
const calculation = `${currentResult} ${method} ${userInput.value}`;
currentResult = eval(calculation);
outputResult(currentResult, calculation);
}
addBtn.addEventListener('click', ()=> calculate('+'));
subtractBtn.addEventListener('click', ()=> calculate('-'));
multiplyBtn.addEventListener('click', ()=> calculate('*'));
divideBtn.addEventListener('click', ()=> calculate('/'));