Programming Examples

Java script function max to find largest number


Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Javascript. 

Solution

<!DOCTYPE html>
<html>
<head>
	<title>Square and Qube of Number</title>
    <script language="javascript">
	function max(a,b)
	{
		if(a>b)
		{
			return a;
		}
		else
		{
			return b;
		}
		
	}
	
	</script>
</head>

<body>
	<script language="javascript">
	var a,b,c;
	a=parseInt(prompt("Enter First No"));
	b=parseInt(prompt("Enter Second No"));
	c=max(a,b);
	alert("largest No is "+c);
	</script>
</body>
</html>
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz