Skip to content

Commit 96e3fdb

Browse files
committed
modified: Sprint-1/1-key-exercises/2-initials.js
modified: Sprint-1/1-key-exercises/3-paths.js modified: Sprint-1/1-key-exercises/4-random.js
1 parent bae8316 commit 96e3fdb

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ 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+
// You can use the .charAt() method of strings to get a character at a specific position in a string.
9+
// The first character is at position 0, the second at position 1, and so on.
10+
11+
12+
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
913

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

16+
// Log the initials variable to the console
17+
console.log(initials);
18+

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ 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+
// The dir part is everything before the base part
21+
// The ext part is everything after the last "." in the base part
22+
23+
// You can use the .lastIndexOf() method of strings to find the position of the last occurrence of a specific character in a string.
24+
// For the dir part, you need to find the position of the last "/" in the filePath string.
25+
// For the ext part, you need to find the position of the last "." in the base string.
26+
27+
const dir = filePath.slice(0, lastSlashIndex + 1); // this will include the last "/"
28+
// if you don't want the last "/", use lastSlashIndex instead of lastSlashIndex + 1
29+
30+
const ext = base.slice(base.lastIndexOf(".")); // this will include the "."
31+
// if you don't want the ".", use filePath.lastIndexOf(".") + 1 instead of filePath.lastIndexOf(".")
32+
33+
console.log(`The dir part of ${filePath} is ${dir}`);
34+
console.log(`The ext part of ${filePath} is ${ext}`);
2235

2336
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ 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 is a variable that stores a random integer between minimum and maximum.
8+
// the num variable is calculated using the Math.random() function, which generates a random floating-point number between 1 and 100.
9+
710
// Try breaking down the expression and using documentation to explain what it means
11+
// const num stores the result of the expression on the right-hand side of the equals sign
12+
// the = expression is used to assign a value to a variable
13+
// the expression (maximum - minimum + 1) calculates the range of numbers between minimum and maximum.
14+
// adding minimum shifts the range to start from the minimum value instead of 0.
15+
816
// It will help to think about the order in which expressions are evaluated
17+
// 1. (maximum - minimum + 1) is evaluated first, resulting in 100
18+
// 2. Math.random() is called, generating a random floating-point number between 0 (inclusive) and 1 (exclusive)
19+
// 3. The result of Math.random() is multiplied by the result of (maximum - minimum + 1), scaling the random number to the desired range
20+
//
21+
922
// Try logging the value of num and running the program several times to build an idea of what the program is doing
23+
// The running the the program several times you can see that the program is generating a random number between 1 and 100.
24+
25+
console.log(num);

0 commit comments

Comments
 (0)