Skip to content

Commit dc792ba

Browse files
solving exercise 4-random
1 parent d1507f1 commit dc792ba

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,29 @@ 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+
//console.log(num);
12+
13+
//First operation
14+
// num is generating a random floating number with method Math.random() between 0 and 1
15+
16+
let test = Math.random()
17+
console.log(test)
18+
19+
//Second operation
20+
//The generated number is multiplied by 100 being (maximum =100 -1 +1)
21+
22+
test =Math.random() *(maximum - minimum +1);
23+
console.log(test)
24+
25+
//Third operation
26+
//num is rounded down to the nearset whole number using the method Math.floor
27+
28+
test = Math.floor(Math.random() * (maximum - minimum + 1))
29+
console.log(test)
30+
31+
// Last operation is to add 1 to num 1 is stored in a variable called minimum
32+
33+
test =Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
34+
console.log(test)
35+
console.log(num)

0 commit comments

Comments
 (0)