I want to write a JavaScript conditional statement to find the sign of product of three numbers. Display an alert box with the specified sign. The three numbers have to be written in input fields. And when I click on an OK button, it should tell me what sign of product I have. Is it a postive number(+) or negative(-)?
<body>
Please enter numbers that aren't 0.
<input id="x" type="text" name="" value="">
<input id="y" type="text" name="" value="">
<input id="z" type="text" name="" value="">
<button type="onclick" onclick="value()" name="button">OK</button>
<script>
function value() {
document.getElementById('x').innerHTML;
document.getElementById('y').innerHTML;
document.getElementById('z').innerHTML;
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 if (x<0 && y>0 && z<0)
{
alert("The sign is +");
}
else
{
alert("The sign is -");
}
}
</script>
</body>
</html>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…