I am working on a simple calculator using HTML, CSS, and JavaScript. The calculator displays numbers and operators correctly, but when I press the "=" button to evaluate the expression, I get an error in the console:
Uncaught ReferenceError: evall is not defined at calculate (index.html:49) at HTMLButtonElement.onclick (index.html:37) Code: HTML:
<input type="text" class="display" id="display" disabled>
<button class="equal" onclick="calculate()">=</button>
JavaScript Code:
function calculate() {
try {
document.getElementById("display").value = evall(document.getElementById("display").value); // Possible issue here
} catch (error) {
document.getElementById("display").value = "Error";
}
}
The error message suggests that evall is not recognized.
This post provides enough context and details for Stack Overflow users to understand your issue and offer solutions. Let me know if you need any modifications!
I am working on a simple calculator using HTML, CSS, and JavaScript. The calculator displays numbers and operators correctly, but when I press the "=" button to evaluate the expression, I get an error in the console:
Uncaught ReferenceError: evall is not defined at calculate (index.html:49) at HTMLButtonElement.onclick (index.html:37) Code: HTML:
<input type="text" class="display" id="display" disabled>
<button class="equal" onclick="calculate()">=</button>
JavaScript Code:
function calculate() {
try {
document.getElementById("display").value = evall(document.getElementById("display").value); // Possible issue here
} catch (error) {
document.getElementById("display").value = "Error";
}
}
The error message suggests that evall is not recognized.
This post provides enough context and details for Stack Overflow users to understand your issue and offer solutions. Let me know if you need any modifications!
Share Improve this question edited Jan 31 at 10:47 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Jan 31 at 10:20 Aleena JaneAleena Jane 11 bronze badge 2 |1 Answer
Reset to default 1I don't know if you have figured this out yet but I think your issue is that evall isn't a JS function, but eval is. The quick code fix is this:
document.getElementById("display").value = eval(document.getElementById("display").value);
However, .eval does have some security issues, and also make sure to remove the disabled tag in the input.
Hope this helps!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269186a4619640.html
The error message suggests that evall is not recognized.
So, whats the question? Define a functionevall
. – tkausl Commented Jan 31 at 10:22evall
– Hmmmmm Commented Jan 31 at 10:23