Skip to content

Commit 9a013e1

Browse files
author
russom
committed
Explain how the code works
1 parent e43b31e commit 9a013e1

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
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+
// 1. num is a variable that stores the final result of the expression assigned to it.
12+
// 2. The Math.random() method generates a random decimal number from 0 up but not excluding 1.
13+
// 3. The Math.floor() method round a decimal number down to a whole number.
14+
// 4. (maximum - minimum + 1) calculates how many possible whole numbers there are.
15+
// Java Script evaluates the expressions inside the inner parentheses first.
16+
// + minimum adds 1 to move the range from 0 to the minimum 1.

0 commit comments

Comments
 (0)