File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,17 @@ const maximum = 100;
44const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
55console . log ( num ) ;
66// In this exercise, you will need to work out what num represents?
7+ // num represents random whole number between 1 to 100
8+ //It is generated by:
9+ //Creating a random decimal between 0 and 1 using Math.random()
10+ //Scaling it to the range 1 to 100
11+ //Rounding it down using Math.floor() so it becomes an integer
12+
713// Try breaking down the expression and using documentation to explain what it means
814// It will help to think about the order in which expressions are evaluated
915// Try logging the value of num and running the program several times to build an idea of what the program is doing
16+ // Math.random() produces a random decimal number between 0 (inclusive) and 1 (exclusive). example : .10,.23 etc
17+ //it will never return 1
18+ // scale the random decimal number using multiplication with 100(maximum-minimum+1)
19+ //Math.floor() this method will remove the decimal part and return the nearest integer from 0 to 99
20+ // +minimum will shift the range from 0 to 99 to 1 to 100.
You can’t perform that action at this time.
0 commit comments