You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// In this exercise, you will need to work out what num represents?
7
7
// Try breaking down the expression and using documentation to explain what it means
8
8
// It will help to think about the order in which expressions are evaluated
9
9
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10
+
11
+
//Answers
12
+
// num is a constant variable that stores a random integer between the minimum and maximum values (inclusive), generated using Math.random() and Math.floor()
13
+
14
+
15
+
16
+
// Math.random()
17
+
// This expression gives you a random decimal number between 0 and 1.
18
+
// It could be something like 0.25 or 0.879, but it will never reach 1.
19
+
20
+
// (maximum - minimum + 1)
21
+
// This expression calculates how many numbers are in the range you want.
22
+
// For example, if your range is 1 to 100, the result is 100 because there are 100 possible values.
23
+
24
+
// Math.random() * (maximum - minimum + 1)
25
+
// This expression multiplies the random decimal by your range.
26
+
27
+
28
+
// Math.floor(...)
29
+
// This expression rounds the number down to the nearest integer.
30
+
// For example, 37.6 becomes 37, and 99.9 becomes 99.
31
+
32
+
// + minimum
33
+
// Variable minimum is added to the expression "Math.floor(Math.random() * (maximum - minimum + 1))" and the the value is stored inside the variable num
0 commit comments