class Calculator {
constructor() {
console.log(`Enter the numbers and the operation index you want to perform:
1) Addition
2) Substraction
3) Multiplication
4) Division`);
this.calculate();
}
/**
* @param {number} firstValue get the first value
* @param {number} secondValue get the second value
*/
addition(firstValue, secondValue) {
return firstValue + secondValue;
}
/**
* @param {number} firstValue get the first value
* @param {number} secondValue get the second value
*/
subtraction(firstValue, secondValue) {
return firstValue - secondValue;
}
/**
* @param {number} firstValue get the first value
* @param {number} secondValue get the second value
*/
multiplication(firstValue, secondValue) {
return firstValue * secondValue;
}
/**
* @param {number} firstValue get the first value
* @param {number} secondValue get the second value
*/
division(firstValue, secondValue) {
if (secondValue != 0) {
return firstValue / secondValue;
}
return 'Cannot perform division by 0';
}
calculate() {
prompt.get(propertiesPrompt, (error, values) => {
if (error) {
throw new Error(error);
}
console.log(operationResult[values.operation](values.valueOne, values.valueTwo));
prompt.get(choiceResponse, (responseError, response) => {
if (responseError) {
throw new Error(responseError);
}
if (response.optionSelected.toLowerCase() == 'y') {
this.calculate()
}
});
});
}
}
В приведенном выше коде я хочу удалить параметры в моих методах сложения, вычитания, вычисления и деления и установить свойство переменной в классе, чтобы я мог напрямую вызывать сохраненные значения в методах и сделать операцию. Как это можно сделать?