using the .reduce() method
I'm trying to use the reduce method on the numbersToSum array (bottom of the code), but it doesn't seem to work. I'm a beginner with javascript and i've never used this method, can someone help? let displayField = document.querySelector('input'); let digit = document.querySelector('.digit'); let numbersDigit = document.querySelector('.number-btn'); let operations = document.querySelector('.operation-btn'); let numbersToSum = []; displayField.value = ''; //digit numbers in display digit.addEventListener('click', (e) => { if(e.target.className === 'number-btn'){ displayField.value += e.target.innerHTML; } //storing numbers in the array if(e.target.className === 'sum-btn'){ numbersToSum.push(parseInt(displayField.value)); displayField.value = ''; console.log(numbersToSum); //summing the numbers if(e.target.className === 'result-btn'){ numbersToSum.reduce((total, num)=>{ return total + num; }); console.log(numbersToSum) } } })