Java Script


JavaScript Tutorial


Admission Enquiry Form


Check positive, negative or zero using if else if

Example:

<html>
<head>
<title> positive negative using if else if</title>
</head>

<body>
<script>
var num;
num=10;
if(num==0)
{
document.write(" It is zero ");
}
else if(num>0)
{
document.write(" It is positive ");
}
else if(num<0)
{
document.write(" It is negative ");
}

</script>
</body>
</html>

Check positive, negative or zero in if else if using prompt() function

Example:

<html>
<head>
<title>positive negative in if else if using prompt</title>
</head>

<body>
<script>
var num;
num=parseInt(prompt("Enter a number"));
if(num==0)
{
document.write(" It is zero ");
}
else if(num>0)
{
document.write(" It is positive ");
}
else if(num<0)
{
document.write(" It is negative ");
}

</script>
</body>
</html>


Check positive, negative or zero in if else if on Button click using function

Example:

<html>
<head>
<title>positive negative in if else if using function</title>
<script>
function pos_neg()
{
var num;
num=parseInt(prompt("Enter a number"));
if(num==0)
{
document.write(" It is zero ");
}
else if(num>0)
{
document.write(" It is positive ");
}
else if(num<0)
{
document.write(" It is negative ");
}
}
</script>

</head>

<body>
<input type="button" value="click" onClick="pos_neg()">
</body>
</html>