I'm not precisely sure about what causes this error in my code but I guess it's the poor approach of addressing a parameter in the resualtValues function. ** thank u all in advance.**
const calculator = {
sum:[],
subtraction:[],
multiplication:[],
division:[],
sumValues:function(num1,num2){
this.sum.push({
num1: num1,
num2: num2,
})
},
subtractionValues:function(num1,num2){
this.subtraction.push({
num1: num1,
num2: num2,
})
},
multiplyValues:function(num1,num2){
this.multiplication.push({
num1: num1,
num2: num2,
})
},
divisionValues:function(num1,num2){
this.division.push({
num1: num1,
num2: num2,
})
},
resualtValues: function(){
return this.sum.forEach(function(item){
return item.num1 + item.num2
})
}
}
calculator.sumValues(25,4)
calculator.subtractionValues(20,5)
calculator.multiplyValues(5,6)
calculator.divisionValues(45,5)
console.log(calculator.resualtValues())
I wanted to define some functions so when I call them they pass the given parameters to the arrays that inhabited in calculator object so that the resualtValues function use these parameters and operate four basic math operations.