Skip to content

Commit 739e416

Browse files
committed
1-key-exercises are done
1 parent 3372770 commit 739e416

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ 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 is assigning (count + 1) to the variable count.
9+
// In other word adding 1 to the variable count.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ 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 = ``;
8+
let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`;
9+
console.log(initials);
10+
console.log(typeof initials);
911

1012
// https://www.google.com/search?q=get+first+character+of+string+mdn
1113

14+
// I used the mdn documentation to know how to get the first character of a string.
15+
// I used charAt() method that takes the index of a string and return the character of it.

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111

1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
14-
const base = filePath.slice(lastSlashIndex + 1);
14+
const base = filePath.slice(-8);
1515
console.log(`The base part of ${filePath} is ${base}`);
1616

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, -8);
21+
const ext = filePath.slice(filePath.length-3);
2222

23-
// https://www.google.com/search?q=slice+mdn
23+
console.log(`the dir part of filePath variable is ${dir}`);
24+
console.log(ext);
25+
26+
// https://www.google.com/search?q=slice+mdn
27+
28+
// After studying the slice() method I was able to do this task easily.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
console.log(num);
56

67
// In this exercise, you will need to work out what num represents?
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+
12+
// num is a variable that will be assigned an integer number after the operators are done.
13+
// Math.floor() rounds a decimal to its nearest number to make it an integer. ex = 1.2 => 1.
14+
// Math.random() is a method used to create numbers between (0-1) and usually it creates a decimal like (0,2) or etc.
15+
// each time I run it, I got different number as Math.random() generates different number each time we run it.

0 commit comments

Comments
 (0)