Skip to content

Commit b1e0fc1

Browse files
fixing issues in excersie 4-random
1 parent d386bfb commit b1e0fc1

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const minimum = 10;
1+
const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
@@ -8,28 +8,23 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
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
1010

11-
//console.log(num);
11+
console.log(num);
1212

1313
//First operation
14-
// num is generating a random floating number with method Math.random() between 0 and 1
14+
// num is generating a random dicimal number with method Math.random() between 0 and 1 result eg :0.3948605
15+
1516

16-
let test = Math.random()
17-
console.log(test)
1817

1918
//Second operation
20-
//The generated number is multiplied by 100 being (maximum =100 -1 +1)
19+
//The generated number is multiplied by the range+1 which is between 1-100 result eg 39.48605
2120

22-
test =test *(maximum - minimum +1);
23-
console.log(test)
2421

2522
//Third operation
26-
//num is rounded down to the nearset whole number using the method Math.floor
23+
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
24+
2725

28-
test = test+ minimum;
29-
console.log("test+ minimum" , test)
3026

31-
// Last operation is to add 1 to num 1 is stored in a variable called minimum
27+
// Last operation is to add 1 to hit the maximum value (since Math.random() never quite reaches 1). This ensures all 100 numbers (1 through 100) are equally reachable.eg 39 => 40
3228

33-
test =Math.floor(test)
34-
console.log(test)
35-
//console.log(num)
29+
30+

0 commit comments

Comments
 (0)