JavaScript To Find Greatest Among 3 Numbers

/* The Following Script will display the greatest among three numbers*/

[html]
<html>
<head>
<h1>Greatest Among Three Numbers</h1>
</head>
<body>
<script type="text/javascript">
var a=10,b=20,c=7;

/* checks a>b and a>c  if  both conditions satisfied, A is greater */

if (a>b  && a>c)
{
document.write("<b>A is greater</b>");
}

/* checks b>a  and b>c  if  both conditions satisfied, b is greater */

if (b>a  && b>c)
{
document.write("<b>B is greater</b>");
}

/* if the above two conditions were false c is greater*/

else
{
document.write("<b>C is greater</b>");
}
</script>
</body>
</html>
[/html]

The Output will be:

Greatest Among  Three Numbers

B is Greater


1 Comment to JavaScript To Find Greatest Among 3 Numbers

shilpi
March 30, 2012

thanks 4 the answer

Leave a comment

Request a Free SEO Quote