postheadericon 5. Write a JavaScript to generate two random numbers and find out maximum and minimum out of it.




<html>
<head>
<title>EX-5: WTAD : www.bipinrupadiya.com</title>

<script type="text/javascript">
function bsr()
{
var rnd1=Math.floor(Math.random()*100);
var rnd2=Math.floor(Math.random()*100);
document.write('<br>Random No.1 : ' + rnd1);
document.write('<br>Random No.2 : ' + rnd2);
if (rnd1 < rnd2)
{
document.write('<br><br>Minimum No.:' + rnd1);
document.write('<br>Maximum No.:' + rnd2);
}
else
{
document.write('<br><br>Minimum No.:' + rnd2);
document.write('<br>Maximum No.:' + rnd1);
}
}
</script>

</head>

<body onLoad='bsr();'>

</body>
</html>

3 comments:

pg said...

This is a simple and clear example of using JavaScript’s Math.random() and Math.floor() to generate two values and then compare them to determine the minimum and maximum. The conditional logic is easy to follow, making the example useful for beginners who are learning variables, random number generation, comparison operators, and if-else statements. A Javascript Online Course can provide a broader foundation for these JavaScript programming concepts.

pg said...

I also like that the example keeps the logic compact: two random numbers are generated, displayed, compared, and then the appropriate minimum and maximum values are printed. These basic programming exercises are useful for building the reasoning skills needed before moving into more structured TypeScript development, making a TypeScript Online Course a natural next step for learners progressing from JavaScript fundamentals.

alex said...

I was working through that JavaScript task about generating two random numbers and comparing them for the max and min, and it’s funny how much simpler it looks until you actually write it out. Do you usually rely on Math.max and Math.min, or do you prefer writing your own comparison logic? While debugging, I stumbled across an attractiveness test just to take a quick break and see what it would say.

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.