JavaScript Calculator Program Error - TechRepublic
General discussion
May 1, 2023 at 11:33 AM
gulshan212

JavaScript Calculator Program Error

by gulshan212 . Updated 3 years, 1 month ago

Hello this is Gulshan Negi
Well, I am writing a program for making calculator using JavaScript but it shows some error at the time of its execution.
I am getting error in this phase and here is my source code:

const calculator = {
displayValue: ‘0’,
firstOperand: null,
waitingForSecondOperand: false,
operator: null,
}

function inputDigit(digit) {
const { displayValue, waitingForSecondOperand } = calculator;

if (waitingForSecondOperand === true) {
calculator.displayValue = digit;
calculator.waitingForSecondOperand = false;
} else {
calculator.displayValue = displayValue === ‘0’ ? digit : displayValue + digit;
}
}

function inputDecimal(dot) {
if (calculator.waitingForSecondOperand === true) {
calculator.displayValue = “0.”
calculator.waitingForSecondOperand = false;
return
}

I also checked and took a reference from a site but I dont know what thing I am missing.
Can anyone give their suggestions on this ?
Thanks

Note: URL of site referenced removed by moderator.

This discussion is locked

All Comments