-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomNumberGenerator.html
More file actions
74 lines (49 loc) · 2.29 KB
/
randomNumberGenerator.html
File metadata and controls
74 lines (49 loc) · 2.29 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Test Page</title>
<link rel="stylesheet" href="css/normalize.css">
<!-- <link rel="stylesheet" href="css/style.css"> -->
</head>
<body class="style">
<div class="content" style="text-align: center; margin-top: 50px;">
<script type="text/javascript">
// random number generator, collects two numbers, then writes one between two inputs.
// assignment did not include conditionals, but I added them (found the ifNaN condition on google.)
// prompt for first number, must be number.
var firstNumber = Number(prompt ("Enter a number, then click OK. Note: I will round for you."));
// check if a is number. If yes, prompt next number. If not, write refresh message.
if (isNaN(firstNumber) || typeof firstNumber !== "number") {
alert("Sorry, that wasn't a number. Please refersh the page and try again.");
document.write ("Please refersh the page and try again.");
}
// prompt for second number, must be number. If not, write refresh message.
else {
var secondNumber = Number(prompt ("Enter a second number, then click OK."));
}
// check if b is number. If yes, generate number. If not, write message to refresh.
if (isNaN(secondNumber) || typeof secondNumber !== "number") {
alert("Sorry, that wasn't a number. Please refersh the page and try again.");
} else {
document.write ("You chose " + Math.round(firstNumber) + " and " + Math.round(secondNumber) + "<br><br>");
}
// figure out random number generator component (I had to watch the answer to get the math component)
var randomNumber = (Math.floor(Math.random() * (secondNumber - firstNumber + 1) + firstNumber));
var message = "Your random number is " + randomNumber + ".";
document.write (message);
// random trials
// variables
//var firstNumber = (Math.floor(Math.random()) * 0 ) + Math.floor(a);
//var secondNumber = (Math.floor(Math.random()) * 0 ) + b;
// this always generates number 1.
// document.write ((Math.floor(Math.random()) * 1 ) + 1);
// this always generates zero.
// Math.floor(Math.random());
// do I need these if I'm rounding down?
//parseInt (a);
//parseInt (b);
</script>
</div>
</body>
</html>