I started created a simple calculator using javascript that was able to calculate values with basic operators and decimals and everything was working well. I then decided I wanted to expand the calculator so I created a new design for the calculator that included more advanced capabilities and I changed around the variable and function names to make them more easy to understand and now I’m getting an Uncaught ReferenceError: (line labeled below)
var equal = document.getElementById('equals');
equal.addEventListener('click', function () {
var equalSign = document.getElementById('equalSign');
var fixedExpress="";
if (isValidExpress() === true) {
fixedExpress = calcExpress();
resNum = eval(fixedExpress); //getting error from this line
} else {
resNum = "Not Valid Expression";
}
expressOut.firstChild.nodeValue = expressStr + equalSign.firstChild.nodeValue;
resOut.firstChild.nodeValue = resNum;
isDoneEval = true;
});
I’ve been going back and forth between my old and new code and I can’t figure out why they look similar but aren’t evaluating the same. I’ve looked up some ideas and I’ve seen a couple places that suggest that you can’t assign a variable to the value of a function. But if that’s the case, why did it work the first time and how do I fix the problem now?
I’ve also looked at the above function in the console step by step, with dummy values and it looks like everything is working correctly.
Here’s a link to the most recent calculator project I’ve been working on:
Here’s a link to the original calculator that is working how I expect:
Thanks in advance!