- Input elements have a
value
not,innerHTML
- Even if you would have corrected that, you will not have values, since you did not assign them to any variable
- For number only
input
use thenumber
type, this will prevent someone from entering not numeral characters (in all modern browsers)
document.getElementById('check-value').addEventListener('click', (e) => {
const x = document.getElementById('x').value;
const y = document.getElementById('y').value;
const z = document.getElementById('z').value;
if (x + y + z >= 0) {
alert("The sign is +");
} else if (x < 0 && y < 0 && z < 0) {
alert("The sign is +");
} else if (x > 0 && y < 0 && z < 0) {
alert("The sign is +");
} else if (x < 0 && y > 0 && z < 0) {
alert("The sign is +");
} else {
alert("The sign is -");
}
});
Please enter numbers that aren't 0.<br>
<input id="x" type="number" name="" value="">
<input id="y" type="number" name="" value="">
<input id="z" type="number" name="" value="">
<button type="button" id="check-value" name="button">OK</button>
8
solved Write a JavaScript conditional statement to find the sign of product of three numbers. Display an alert box with the specified sign