javascript find max between two numbers

      No Comments on javascript find max between two numbers

javascript find max between two numbers

GTU WTAD Practical 5 : Write a JavaScript to generate two random numbers and find out maximum and minimum out of it.

javascript find max between two numbers

This JavaScript Example Explains the use of random method of Math Class in JavaScript. Here using random method i have generated two numbers and after i will verify maximum and minimum out of both number. Random number is very useful in any programming language, specially to generated OTP like code or to generate unique number to verify users. You can modify this example and use it as per your requirements.

GTU WTAD Practical 7

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu_05\

<html>
<head>
	<title> GTU WTAD Practical 5 : Write a JavaScript to generate two random numbers and find out maximum and minimum out of it. </title>

	<script language="javascript">
			function rand(ele)
			{
				generated_no=Math.floor(Math.random()*100+1)
				ele.value=generated_no
			}
			function check()
			{
				no1=parseInt(document.getElementById("random_no1").value)
				no2=parseInt(document.getElementById("random_no2").value)
				
				if(no1>no2)
					document.getElementById("msg").innerHTML=no1 +" Number is Greater " + "<br>"
				else
					document.getElementById("msg").innerHTML=no2 +" Number is Greater " + "<br>"	
			}
	</script>
</head>
<body>
	<center> <h2> GTU WTAD Practical 5 : Write a JavaScript to generate two random numbers and find out maximum and 
minimum out of it. </h2></center>
	
	<b>Random Number (Between 0-100) 1 : </b> <input type="text" size="10" id="random_no1">
	<input type="Button" value="Click To Generate Random Number 1" onClick="rand(random_no1)">
	<br><br>
	<b>Random Number (Between 0-100) 2 :</b> <input type="text" size="10" id="random_no2">
	<input type="Button" value="Click To Generate Random Number 2" onClick="rand(random_no2)">
	<br><br>
	<input type="Button" value="Find Max Number" onClick="check()"><br>
	<p><div id="msg" style=background-color:pink;></div></p>


</body>
</html>

 

Output

GTU WTAD Practical 5

 

 

Leave a Reply