I encountered an issue that is causing me to receive the following error message:
TypeError: Cannot read property 'sum' of undefined
How can this be resolved?
function calculator(firstNumber) {
var result = firstNumber;
function sum() {
for (let i = 0; i <= arguments.lenght; i++) {
result += arguments[i];
}
return result;
}
function dif() {
for (let i = 0; i <= arguments.lenght; i++) {
result -= arguments[i];
}
return result;
}
}
var myCalculator = calculator(10);
console.log(myCalculator.sum(2, 3));
console.log(myCalculator.dif(1, 2, 5));
The expected output should be:
15
2