Skip to content

Commit 8fc0686

Browse files
author
Pretty Taruvinga
committed
answered a question
1 parent 3372770 commit 8fc0686

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ let count = 0;
22

33
count = count + 1;
44

5+
console.log(count);
56
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
67
// Describe what line 3 is doing, in particular focus on what = is doing
8+
9+
// Answer
10+
// Line 3 is an assignment operation. The = operator assigns the value of the expression on its right
11+
// (count + 1) to the variable on its left (count). This effectively increments the value of count by 1.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ let lastName = "Johnson";
44

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.
7-
8-
let initials = ``;
7+
//
8+
let initials = firstName[0] + middleName[0] + lastName[0];
99

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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(".") + 1);
2222

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
// Answer
11+
// The expression generates a random integer between the minimum and maximum values (inclusive).
12+
// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
13+
// Multiplying this by (maximum - minimum + 1) scales it to the range of possible integers.
14+
// Adding minimum shifts the range to start from the minimum value.
15+
// Finally, Math.floor() rounds down to the nearest whole number, ensuring that num is an integer within the specified range.

0 commit comments

Comments
 (0)