Skip to content

Commit 92aee19

Browse files
committed
completed task in 4-random.js
1 parent 678fe4c commit 92aee19

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sprint-1/1-key-exercises/4-random.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5-
5+
console.log(num)
66
// In this exercise, you will need to work out what num represents?
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
// Math.random() generates a random decimal number from 0 to less than 1
12+
// Math.floor() rounds down to the nearest whole number
13+
// maximum-minimum+1 gives 100
14+
// Math.random() * (maximum - minimum + 1) gives a random decimal number between 0 and less than 100, and Math.floor() rounds it down to the nearest integer to give a range of 0 to 99, and by adding minimum 1 to it, num is a random integer between 1 and 100 inclusive

0 commit comments

Comments
 (0)