Skip to content

Commit 1771147

Browse files
committed
Sprint -1 is done: except the first one, which i submit earlier, the rest is done in this commit . i.e. 2 -initials done, 3-path done , 4 random is done.
1 parent abb16d7 commit 1771147

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let 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-
let initials = ``;
9-
8+
let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
9+
console.log(initials);
1010
// https://www.google.com/search?q=get+first+character+of+string+mdn
1111

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ 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 = ;
22-
20+
const dir = filePath.slice(0,lastSlashIndex);
21+
const ext = base.slice(base.lastIndexOf("."));
22+
console.log (`The directory is : ${dir}
23+
The extension is : ${ext}`);
2324
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ const maximum = 100;
44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
7+
// num represents a random integer between 1 and 100.
78
// Try breaking down the expression and using documentation to explain what it means
89
// It will help to think about the order in which expressions are evaluated
910
// Try logging the value of num and running the program several times to build an idea of what the program is doing
11+
// breaking down the expression into smaller parts.
12+
/* Math.floor(): this will return the largest integer less than or equal to a given number. In this case, it will round down the result of the expression inside the parentheses.
13+
Math.random(): this will return a random floating-point number between 0 (inclusive) and 1 (exclusive). In this case, it will generate a random number between 0 and 1 but never exactly 1.
14+
(maximum - minimum + 1): this will calculate the range of numbers we want to generate. In this case, it will calculate the difference between the maximum and minimum values (100 - 1 = 99)
15+
and add 1 to include both endpoints (99 + 1 = 100).
16+
finally, the code adds the minimum value (which is 1) to the result.
17+
*/
18+

0 commit comments

Comments
 (0)