From 13ca8bc8d0ccef5297eca0543ca25667306a55b2 Mon Sep 17 00:00:00 2001 From: lintsang Date: Fri, 12 Jun 2026 07:19:30 +0100 Subject: [PATCH 1/8] adding answer to exercise 1 --- Sprint-1/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..7661d75c53 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ count = count + 1; // 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 + +//Line 3 is a statement. Here we reassign the value of count from 0 to 1 by adding value one to it \ No newline at end of file From 50829363e146964dff9937a6744b057e58adeae2 Mon Sep 17 00:00:00 2001 From: lintsang Date: Fri, 12 Jun 2026 20:51:30 +0100 Subject: [PATCH 2/8] try method use to take first letter --- Sprint-1/1-key-exercises/2-initials.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..09332e273a 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,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.charAt(0); +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From 851b51c67345f2e5b6146734f8f820998f1e1907 Mon Sep 17 00:00:00 2001 From: lintsang Date: Fri, 12 Jun 2026 21:39:58 +0100 Subject: [PATCH 3/8] add the other two initials to the string --- Sprint-1/1-key-exercises/2-initials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 09332e273a..10cc52f0ab 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ 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 = firstName.charAt(0); +let initials = firstName.charAt(0)+middleName.charAt(0)+lastName.charAt(0); console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From ad440937e688d0581ca46fbcb50788f30cb1886c Mon Sep 17 00:00:00 2001 From: lintsang Date: Sat, 13 Jun 2026 16:03:33 +0100 Subject: [PATCH 4/8] extract dir path from the filepath and print it in 3paths.js --- Sprint-1/1-key-exercises/3-paths.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..87c522b0aa 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,9 +15,14 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +function dirString(filePath){ + const dirName = filePath.slice(0,lastSlashIndex); + return dirName; +} // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = dirString(filePath); +console.log(dir); +//const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 8937892eb0ab4b5d28876635077f6ee876236ccd Mon Sep 17 00:00:00 2001 From: lintsang Date: Sat, 13 Jun 2026 16:21:46 +0100 Subject: [PATCH 5/8] extract the extension type of the filepath and print it --- Sprint-1/1-key-exercises/3-paths.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 87c522b0aa..3207515849 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -15,14 +15,22 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable -function dirString(filePath){ - const dirName = filePath.slice(0,lastSlashIndex); +function dirString(){ + const dirName = filePath.slice(1,lastSlashIndex); return dirName; } + // Create a variable to store the ext part of the variable +function extString(){ + const lastDotIndex = filePath.lastIndexOf("."); + const extName = filePath.slice(lastDotIndex); + return extName; +} const dir = dirString(filePath); +const ext = extString(filePath); console.log(dir); +console.log(ext); //const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 8948db2cb19e2b1ab45bb4f8046fd2215ad9d4d4 Mon Sep 17 00:00:00 2001 From: lintsang Date: Sat, 13 Jun 2026 16:23:10 +0100 Subject: [PATCH 6/8] remove unnecessary comment line --- Sprint-1/1-key-exercises/3-paths.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 3207515849..1e9adc0328 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -31,6 +31,5 @@ const dir = dirString(filePath); const ext = extString(filePath); console.log(dir); console.log(ext); -//const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From ff9535b347ede6f6f87d1a3d275252fb062a0bea Mon Sep 17 00:00:00 2001 From: lintsang Date: Sat, 13 Jun 2026 23:12:18 +0100 Subject: [PATCH 7/8] Declare a variable to store the random number and check if the output is as expected --- Sprint-1/1-key-exercises/4-random.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..66ee32ca05 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,7 +1,9 @@ const minimum = 1; const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +const randomNo = Math.random(); +console.log(randomNo); +const num = Math.floor(randomNo * (maximum - minimum + 1)) + minimum; +console.log(num); // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means From b27013917df1b1fefd0adcdf3772adf6434b7c72 Mon Sep 17 00:00:00 2001 From: lintsang Date: Sat, 13 Jun 2026 23:48:54 +0100 Subject: [PATCH 8/8] Add comment to explain the break down what num represents --- Sprint-1/1-key-exercises/4-random.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 66ee32ca05..d8fd5d4bb7 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,11 +1,18 @@ const minimum = 1; const maximum = 100; -const randomNo = Math.random(); -console.log(randomNo); -const num = Math.floor(randomNo * (maximum - minimum + 1)) + minimum; +const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; console.log(num); // In this exercise, you will need to work out what num represents? // 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 + +//In the declaration of num, we can break it down to below: + +//1. A randon number, which is with decimals between 0 and 1, is created by method Math.random() +//2. The random number in step 1 is multipled by 100. That makes an number with decimals. +//3. The method Math.floor grounded the number in step 2 down to a whole number between 0 - 99. +//4. The number from step 3 is added 1, so it makes a whole number between 1-100. + +//I think the overall javascript code here is to make a random whole number between 1-100. \ No newline at end of file