Skip to content

Commit f0db277

Browse files
Complete 1-key-exwecises in Sprint-2
1 parent d28242a commit f0db277

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎Sprint-2/1-key-exercises/1-count.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
8+
// Line 3 takes the current value of count (0), adds 1 to it (0 + 1 = 1), and uses the assignment operator (=) to reassign and store this new value (1) back into the count variable.

‎Sprint-2/1-key-exercises/2-initials.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

8-
const initials = ``;
8+
const initials = firstName[0] + middleName[0] + lastName[0];
99

10+
console.log(initials);
1011
// https://www.google.com/search?q=get+first+character+of+string+mdn

‎Sprint-2/1-key-exercises/3-paths.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = filePath.slice(filePath.lastIndexOf("."));
2222

23+
console.log(dir);
24+
console.log(ext);
2325
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

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
6+
console.log(num);
7+
// what does num represent?
8+
// num represents a random whole number (integer) between minimum (1) and maximum (100) inclusive.
9+
10+
//Breakdown of the expression:
11+
// 1. Math.random() generates a decimal number from 0 (inclusive) up to, but not including, 1.
12+
// 2. (maximum - minimum + 1) calculates the range size (100 - 1 + 1 = 100).
13+
// 3. Math.random() * 100 scales the random decimal to a range between 0 and 99.999...
14+
// 4. Math.floor() rounds that value down to the nearest whole integer (0 to 99).
15+
// 5. + minimum (+ 1) shifts the final value up into the target range of 1 to 100.

0 commit comments

Comments
 (0)