-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrng.js
30 lines (20 loc) · 863 Bytes
/
rng.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$(document).ready(function(){
$("button").click(function(){
var inputLB = document.getElementById("inputLB").value;
var inputRB = document.getElementById("inputRB").value;
var outputh1 = document.getElementById("outputh1");
if( (inputLB != "") && (inputRB != "") && !isNaN(inputLB) && !isNaN(inputRB) ) {
var intLB = parseInt(inputLB);
var intRB = parseInt(inputRB);
outputh1.innerHTML = "Your num is " + getRandomIntInclusive(intLB, intRB);
}
else {
alert("type a number or something");
}
});
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
}
});