I tried to get my result printed on calculator display screen but when i checked the error it said "
calculator.js:14 Uncaught TypeError: Cannot read properties of undefined (reading 'getAttribute')
at HTMLButtonElement.<anonymous>"
Here is the code below:
var display = document.getElementById("calculator_display");
var point = document.getElementsByClassName("calc_button");
var operand1 = 0;
var operand2 = null;
var operator = null;
for (var i = 0; i < point.length; i++) {
point[i].addEventListener("click", () => {
var value = point[i].getAttribute("data-value");
// var value= this.Array.getAttribute("data-value");
if (value == "+") {
operator = "+";
operand1 = parseFloat(display.textContent)
}
else if (value == "=") {
operand2 = parseFloat(display.textContent);
var ans = eval(operand1 + " " + operator + " " + operand2);
display.innerHTML = ans;
}
else {
// console.log(display.innerHTML);
display.innerHTML += display.innerHTML + value;
}
})
}
I tried to get the calculator number get displayed on pressing respective buttons.