In: Computer Science
Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value.
var ival = IntRandomRange(, );
Program:
<html>
<head>
<script language="javascript">
function IntRandomRange(minValue,maxValue)
{
var value;
value=Math.floor(Math.random()*maxValue+minValue);
return value;
}
</script>
</head>
<body>
<script language="javascript">
var max,min;
min=parseInt(prompt("Enter the minimum value: "));
max=parseInt(prompt("Enter the maximum value: "));
var ival=IntRandomRange(min,max);
document.write("Minimum value: "+min);
document.write("<br>Maximum value: "+max);
document.write("<h3>A random number between "+min+" and
"+max+" is "+ival+"</h3>");
</script>
</body>
</html>
Output: