admin管理员组文章数量:1417578
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!
本文标签: An error in JS code about a Calculator that show me quotERRORquot resultStack Overflow
版权声明:本文标题:An error in JS code about a Calculator that show me "ERROR" result - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745269186a2650785.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