For Advertisements on this blog Contact Us at developgram@gmail.com or +91-9923438816

Simple Programming Tutorials For Beginners

Wednesday, April 19, 2017

Greatest Number

<html>
 <body>
  <script>
  var n1, n2, n3;

  n1 = parseInt(prompt("Enter the first number"));
  n2 = parseInt(prompt("Enter the second number"));
  n3 = parseInt(prompt("Enter the third number"));

  /*
  Using Conditional Operator
  (n1 > n2 && n1 > n3) ? document.write(n1 + " is greatest number") : (n2 > n3 && n2 > n1) ? document.write(n2 + " is greatest number") : document.write(n3 + " is greatest number");
  */

  //Using if else statement
  if (n1 > n2)
   greater = n1;
  else
   greater = n2;

  if (n3 > greater)
   greatest = n3;
  else
   greatest = greater;

  document.write(greatest + " is greatest number");
  </script>
 </body>
</html>


No comments:

Post a Comment

SEARCH THIS BLOG