enter image description here it shows Nan when there is no number, how can a disable it?
Disable the buttons in html by adding a disabled attribute. Write an on-change handler for the inputs where the buttons are enabled only if there is value.
Ref: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event
const input1 = document.querySelector('#num1');
const input2 = document.querySelector('#num2');
input1.addEventListener('change', handleButton);
input2.addEventListener('change', handleButton);
function handleButton() {
if(input1.value && input2.value) {
document.querySelector(".button").removeAttribute("disabled");
} else {
document.querySelector(".button").setAttribute("disabled", "disabled");
}
}
You can target the buttons by the classname which you have used. I have used .button in the answer.