From 8fc068602dbcbba50c0f754ef9c590faa0141f59 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Mon, 9 Feb 2026 11:10:17 +0200 Subject: [PATCH 1/2] answered a question --- Sprint-1/1-key-exercises/1-count.js | 5 +++++ Sprint-1/1-key-exercises/2-initials.js | 4 ++-- Sprint-1/1-key-exercises/3-paths.js | 4 ++-- Sprint-1/1-key-exercises/4-random.js | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..42f16c337 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -2,5 +2,10 @@ let count = 0; count = count + 1; +console.log(count); // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + +// Answer +// Line 3 is an assignment operation. The = operator assigns the value of the expression on its right +// (count + 1) to the variable on its left (count). This effectively increments the value of count by 1. \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..6b1cf0f16 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -4,8 +4,8 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. - -let initials = ``; +// +let initials = firstName[0] + middleName[0] + lastName[0]; // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..fbe113e0f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".") + 1); // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..baa81c1c3 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing +// Answer +// The expression generates a random integer between the minimum and maximum values (inclusive). +// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive). +// Multiplying this by (maximum - minimum + 1) scales it to the range of possible integers. +// Adding minimum shifts the range to start from the minimum value. +// Finally, Math.floor() rounds down to the nearest whole number, ensuring that num is an integer within the specified range. \ No newline at end of file From 373185ad6c24627c9a59f5193c1d30fc4cfc36ef Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Mon, 9 Feb 2026 16:01:41 +0200 Subject: [PATCH 2/2] answered questions 2 and 3 --- Sprint-1/1-key-exercises/2-initials.js | 1 + Sprint-1/1-key-exercises/3-paths.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 6b1cf0f16..116b24c99 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -7,5 +7,6 @@ let lastName = "Johnson"; // let initials = firstName[0] + middleName[0] + lastName[0]; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index fbe113e0f..dc0e222b2 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -20,4 +20,6 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = filePath.slice(filePath.lastIndexOf(".") + 1); +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file