Skip to content

Commit b9b2ba8

Browse files
committed
feat: generating number from min and max both inclusive
1 parent f7799bb commit b9b2ba8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Sprint-1/exercises/random.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
// In this exercise, you will need to work out what num represents?
2+
// Try breaking down the expression and using documentation to explain what it means
3+
// It will help to think about the order in which expressions are evaluated
4+
// Try logging the value of num and running the program several times to build an idea of what the program is doing
5+
16
const minimum = 1;
27
const maximum = 100;
38

49
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
10+
//this line will generate a random number between minimum and maximum (inclusive)
11+
// and math.floor will remove decimal part
512

6-
// In this exercise, you will need to work out what num represents?
7-
// Try breaking down the expression and using documentation to explain what it means
8-
// It will help to think about the order in which expressions are evaluated
9-
// Try logging the value of num and running the program several times to build an idea of what the program is doing
13+
Math.floor() //removes decimal part and returns whole number
14+
Math.random() //needs to values between minimum and maximum to generate a random number
15+
16+
console.log(maximum - minimum + 1 ) + minimum; // this is same as 100 - 1 + 1 = 100
17+
console.log(`The random number is ${num}`);

0 commit comments

Comments
 (0)