Question: what errors are in the following javascript? document.getElementById ( button 0 ) . onclick = function ( ) { runCalculator ( 0 )

what errors are in the following javascript? document.getElementById("button0").onclick = function(){
runCalculator(0);
}
document.getElementById("button1").onclick = function(){
runCalculator(1);
}
document.getElementById("button2").onclick = function(){
runCalculator(2);
}
document.getElementById("button3").onclick = function(){
runCalculator(3);
}
document.getElementById("button4").onclick = function(){
runCalculator(4);
}
document.getElementById("button5").onclick = function(){
runCalculator(5);
}
document.getElementById("button6").onclick = function(){
runCalculator(6);
}
document.getElementById("button7").onclick = function(){
runCalculator(7);
}
document.getElementById("button8").onclick = function(){
runCalculator(8);
}
document.getElementById("button9").onclick = function(){
runCalculator(9);
}
document.getElementById("buttonAdd").onclick = function(){
runCalculator("+");
}
document.getElementById("buttonMinus").onclick = function(){
runCalculator("-");
}
document.getElementById("buttonMultiply").onclick = function(){
runCalculator("*");
}
document.getElementById("buttonDivide").onclick = function(){
runCalculator("/");
}
document.getElementById("buttonDecimal").onclick = function(){
runCalculator(".");
}
// Send an empty text string if the Enter key is clicked
document.getElementById("buttonEnter").onclick = function(){
runCalculator("");
}
// Clear the calculator window if the C key is clicked
document.getElementById("buttonClear").onclick = clearCalculator;
// Function to enter characters into the calculator window based on what is clicked
function runCalculator(character){
// Retrieve the characters in the calculator window
let calcValue = document.getElementById("calcWindow").value;
// Add the character to the calculator string or if its empty (the enter key) evaluate the equation
(character)? calcValue += character : calcValue +="="+ evalEq(calcValue)+"
";
// Update the characters displayed in the calculator window.
document.getElementById("calcWindow").value = calcValue;
}
// Function to clear the calculator window
function clearCalculator(){
document.getElementById("calcWindow").value ="";
}
/*=====================================================================*/
// Function to evaluate a text string containing an equation, returning a numeric value to a specified number of decimals
function evalEq(textStr){
var lines = textStr.split(/\r?
/);
var lastLine = lines[lines.length-1];
var eqValue = eval(lastLine);
return eqValue.toFixed(6);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!