JavaScript program to Find largest of Two numbers

In this program, you will take 2 inputs from users using a window prompt, and you will find the largest number.

Program for largest of two number

<!DOCTYPE html>
<html>
  <body>
   <script>
    function Largest2No() {
	  var n1,n2;
	  n1 = parseInt(prompt("enter first number:"));
	  n2 = parseInt(prompt("enter second number:"));
	if(n1>n2)
	{
           document.write(n1+" is Largest number");
	}
	else
	{
	   document.write(n2+" is Largest number");
	}
   }
    </script>
    <form>
      <input type="button" value="LargestNo" onclick="Largest2No()" />
    </form>
  </body>
</html>            
 
Run now

Input has taken through javascript prompt method

output

enter first number:14
enter second number:12
14 is Largest number