You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-1/1-key-exercises/1-count.js
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,3 +4,4 @@ count = count + 1;
4
4
5
5
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
6
6
// Describe what line 3 is doing, in particular focus on what = is doing
7
+
//In line 3 we are taking the current value of count (which is 0) and adding 1 to it, and store the new value back into count" so now count is 1.the = is an assignment operator that Assigns values to variables so it takes the value on the right side (count + 1) and assigns it to the variable on the left side (count).
Copy file name to clipboardExpand all lines: Sprint-1/1-key-exercises/3-paths.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,12 @@ console.log(`The base part of ${filePath} is ${base}`);
17
17
// Create a variable to store the dir part of the filePath variable
18
18
// Create a variable to store the ext part of the variable
19
19
20
-
constdir=;
21
-
constext=;
20
+
constdir=filePath.slice(0,lastSlashIndex);// the slice is a method that cuts out part of a string and returns it as a new string. we use it here to get the dir part of the filePath
21
+
constext=base.slice(base.lastIndexOf("."));//the ext is any thing after the last dot
// In this exercise, you will need to work out what num represents?
7
8
// Try breaking down the expression and using documentation to explain what it means
8
9
// It will help to think about the order in which expressions are evaluated
9
10
// Try logging the value of num and running the program several times to build an idea of what the program is doing
11
+
12
+
//num is a random number between minimum and maximum (inclusive)
13
+
/*Math.random()
14
+
15
+
This gives you a random decimal number between 0 (inclusive) and 1 (exclusive) — meaning it can be 0, but never exactly 1.
16
+
17
+
Example outputs:
18
+
0.23
19
+
20
+
/*(maximum - minimum + 1)
21
+
22
+
This calculates how many whole numbers are in the range, including both ends.
23
+
24
+
Example:
25
+
100 - 1 + 1 = 100
26
+
27
+
So, there are 100 possible integers from 1 to 100.
28
+
29
+
/*Math.random() * (maximum - minimum + 1)
30
+
31
+
This scales the random decimal to the desired range size.
32
+
33
+
Example if Math.random() gave 0.57:
34
+
0.57 * 100 = 57
35
+
/*Math.floor(...)
36
+
The Math.floor() method in JavaScript is used to round a number down to the nearest integer, regardless of whether the number is positive or negative or has a decimal part.
37
+
Example:
38
+
Math.floor(57.8) → 57
39
+
40
+
/*+ minimum
41
+
42
+
Finally, we shift the range up so it starts at 1 instead of 0.
43
+
0–99 becomes 1–100*/
44
+
45
+
//The order for evaluation is:
46
+
/*maximum - minimum + 1
47
+
48
+
Math.random() * (that result)
49
+
50
+
Math.floor(...)
51
+
52
+
+ minimum*/
53
+
54
+
//I run the code several times and got different numbers one was 60 the other one was 88
0 commit comments