From 6626e33ab51cdfe4a56ef5fdd91742dbc1de4066 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 18 Jun 2026 17:37:16 +0100 Subject: [PATCH 01/55] add a comment to answer the question for sprint1 --- 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..8716f0fd4c 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 +//the line 3 is updating the value of the count variable. The `=` operator is an assignment operator that takes the value on the right side (which is `count + 1`, meaning the current value of count plus 1) and assigns it to the variable on the left side (which is `count`). This effectively increments the value of count by 1. + \ No newline at end of file From 268fe9ac26d88984f13fcc6d7093dcc28d3a186c Mon Sep 17 00:00:00 2001 From: Tobias Date: Fri, 19 Jun 2026 16:36:20 +0100 Subject: [PATCH 02/55] using Template literal concept --- 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 47561f6175..4a09edec56 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 = ``; +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; // https://www.google.com/search?q=get+first+character+of+string+mdn From a55b982bda7d9353a2c11e3cb629308494b203e1 Mon Sep 17 00:00:00 2001 From: Tobias Date: Fri, 19 Jun 2026 18:14:12 +0100 Subject: [PATCH 03/55] adding the quotation inside the backtick --- Sprint-1/1-key-exercises/2-initials.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 4a09edec56..432704244b 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[0]}${middleName[0]}${lastName[0]}`; +let initials = `"${firstName[0]}${middleName[0]}${lastName[0]}"`; // https://www.google.com/search?q=get+first+character+of+string+mdn - +console.log(initials); // Output: "CKJ" From 466a1ad0bfd5d1fde69509a5526e3e48853ce76d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 08:10:31 +0100 Subject: [PATCH 04/55] Using slice function to add arrays of string from first to the last slash index --- Sprint-1/1-key-exercises/3-paths.js | 4 ++-- 1 file changed, 2 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..216e3526e0 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); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 90d852d655d56682d11561db74224be8aeb35732 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 08:14:27 +0100 Subject: [PATCH 05/55] using lastIndesOf to locate last dot in arrays and assign it to lasdot variable --- Sprint-1/1-key-exercises/3-paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 216e3526e0..ad17038d77 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -18,6 +18,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the ext part of the variable const dir = filePath.slice(0, lastSlashIndex); +const lastDot = filePath.lastIndexOf("."); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From ac380be0860c7765c617c2f99385f9822bf08092 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 08:17:25 +0100 Subject: [PATCH 06/55] using slice method to add the extention of filename to the ext variable --- Sprint-1/1-key-exercises/3-paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ad17038d77..b3f1c0ded7 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -19,6 +19,7 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const lastDot = filePath.lastIndexOf("."); +const ext = filePath.slice(lastDot); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From be73fdd28afbbb1051346d44a21802c53ebf1505 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 08:18:59 +0100 Subject: [PATCH 07/55] using console method to log the details of dir and ext --- Sprint-1/1-key-exercises/3-paths.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index b3f1c0ded7..9867340e87 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -21,5 +21,8 @@ const dir = filePath.slice(0, lastSlashIndex); const lastDot = filePath.lastIndexOf("."); const ext = filePath.slice(lastDot); +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 From ad02c56df8d8c79923e1e774cec13044b02c5a56 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 08:57:30 +0100 Subject: [PATCH 08/55] breaking done what Math.random method is doing --- Sprint-1/1-key-exercises/4-random.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..c934f979bd 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,5 @@ 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 + +//step 1: Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).so it can be any number from 0 up to but not including 1.e.g 0.5, 0.75, 0.25, 0.1, 0.9, etc. and not 1.0 \ No newline at end of file From fef3716beec63d6c924c7151a0701f05b52a5b7a Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:00:14 +0100 Subject: [PATCH 09/55] explaing what the (maximum -minimum +1 ) is doing with respect to the given values --- Sprint-1/1-key-exercises/4-random.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index c934f979bd..6f0d83796c 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -8,4 +8,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // 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 -//step 1: Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).so it can be any number from 0 up to but not including 1.e.g 0.5, 0.75, 0.25, 0.1, 0.9, etc. and not 1.0 \ No newline at end of file +//step 1: Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).so it can be any number from 0 up to but not including 1.e.g 0.5, 0.75, 0.25, 0.1, 0.9, etc. and not 1.0. +//step 2: (maximum - minimum + 1) calculates the range of numbers we want to generate. In this case, it calculates the difference between the maximum and minimum values (100 - 1 = 99) and adds 1 to include both endpoints of the range. So, it becomes 100.i.e how many numbers are there from 1 to 100 inclusive.e.g 1,2,3,4,5,6,7,8,9,10,...100. so the range is 100. \ No newline at end of file From 0589943941171dbd9c143106750adb5f2edce951 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:04:12 +0100 Subject: [PATCH 10/55] explain what step 3 is doing with respect to Math.random()*(maximum-minimum +1) --- Sprint-1/1-key-exercises/4-random.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 6f0d83796c..9e284348fd 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -9,4 +9,6 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try logging the value of num and running the program several times to build an idea of what the program is doing //step 1: Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).so it can be any number from 0 up to but not including 1.e.g 0.5, 0.75, 0.25, 0.1, 0.9, etc. and not 1.0. -//step 2: (maximum - minimum + 1) calculates the range of numbers we want to generate. In this case, it calculates the difference between the maximum and minimum values (100 - 1 = 99) and adds 1 to include both endpoints of the range. So, it becomes 100.i.e how many numbers are there from 1 to 100 inclusive.e.g 1,2,3,4,5,6,7,8,9,10,...100. so the range is 100. \ No newline at end of file +//step 2: (maximum - minimum + 1) calculates the range of numbers we want to generate. In this case, it calculates the difference between the maximum and minimum values (100 - 1 = 99) and adds 1 to include both endpoints of the range. So, it becomes 100.i.e how many numbers are there from 1 to 100 inclusive.e.g 1,2,3,4,5,6,7,8,9,10,...100. so the range is 100. +//step 3: Math.random() * (maximum - minimum + 1) multiplies the random decimal number generated in step 1 by the range calculated in step 2. This scales the random number to be within the desired range. So, it can be any number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. + From df3dd3b2dbdbe4d04719a1057286918bca0b5818 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:06:05 +0100 Subject: [PATCH 11/55] Explains what step 4 math.floor (..) was doing --- Sprint-1/1-key-exercises/4-random.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 9e284348fd..8173a570b0 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -11,4 +11,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; //step 1: Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).so it can be any number from 0 up to but not including 1.e.g 0.5, 0.75, 0.25, 0.1, 0.9, etc. and not 1.0. //step 2: (maximum - minimum + 1) calculates the range of numbers we want to generate. In this case, it calculates the difference between the maximum and minimum values (100 - 1 = 99) and adds 1 to include both endpoints of the range. So, it becomes 100.i.e how many numbers are there from 1 to 100 inclusive.e.g 1,2,3,4,5,6,7,8,9,10,...100. so the range is 100. //step 3: Math.random() * (maximum - minimum + 1) multiplies the random decimal number generated in step 1 by the range calculated in step 2. This scales the random number to be within the desired range. So, it can be any number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. +//step 4: Math.floor(...) rounds down the result of step 3 to the nearest whole number. This ensures that we get an integer value. so it can be any whole number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. From ae416a63df16fd57604979fec2ea23f40a5dbe5a Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:11:25 +0100 Subject: [PATCH 12/55] Explained what the entire expression on the right hand side was doing --- Sprint-1/1-key-exercises/4-random.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 8173a570b0..c8c9a49c81 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -12,4 +12,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; //step 2: (maximum - minimum + 1) calculates the range of numbers we want to generate. In this case, it calculates the difference between the maximum and minimum values (100 - 1 = 99) and adds 1 to include both endpoints of the range. So, it becomes 100.i.e how many numbers are there from 1 to 100 inclusive.e.g 1,2,3,4,5,6,7,8,9,10,...100. so the range is 100. //step 3: Math.random() * (maximum - minimum + 1) multiplies the random decimal number generated in step 1 by the range calculated in step 2. This scales the random number to be within the desired range. So, it can be any number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. //step 4: Math.floor(...) rounds down the result of step 3 to the nearest whole number. This ensures that we get an integer value. so it can be any whole number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. +//step 5: Math.floor(Math.random() * (maximum - minimum + 1)) + minimum adds the minimum value to the result of step 4. This shifts the range of numbers to start from the minimum value. So, it can be any whole number from 1 up to and including 100.e.g 1, 50, 75, 25, 10, 90, etc. and not 0 or 100. From 5267acec4823770b2801b787ce2e0e45e09d0603 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:16:50 +0100 Subject: [PATCH 13/55] step 5 explains what num stands for --- Sprint-1/1-key-exercises/4-random.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index c8c9a49c81..f9d76fe129 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -13,4 +13,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; //step 3: Math.random() * (maximum - minimum + 1) multiplies the random decimal number generated in step 1 by the range calculated in step 2. This scales the random number to be within the desired range. So, it can be any number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. //step 4: Math.floor(...) rounds down the result of step 3 to the nearest whole number. This ensures that we get an integer value. so it can be any whole number from 0 up to but not including 100.e.g 0, 50, 75, 25, 10, 90, etc. and not 100. //step 5: Math.floor(Math.random() * (maximum - minimum + 1)) + minimum adds the minimum value to the result of step 4. This shifts the range of numbers to start from the minimum value. So, it can be any whole number from 1 up to and including 100.e.g 1, 50, 75, 25, 10, 90, etc. and not 0 or 100. +// In summary, the expression generates a random whole number between the minimum and maximum values (inclusive). In this case, it generates a random whole number between 1 and 100 (inclusive).which is what num represents. From 599cfbd441c1d406f2cf2329811899de9391eb73 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:19:45 +0100 Subject: [PATCH 14/55] used multiple comment syntax to coment out the strings --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..26f73db71c 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +/*This is just an instruction for the first activity - but it is just for human consumption +We don't want the computer to run these 2 lines - how can we solve this problem?*/ \ No newline at end of file From 59a1f60148ca8884ec6fe3dcf2d502293fbcf17e Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 09:38:19 +0100 Subject: [PATCH 15/55] declaring a variable with Const key word doesn't allow reassigning so I used let keyword to declare the variable --- Sprint-1/2-mandatory-errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..e57b2e9791 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); From 1f1249d11ab7f15b730ea93431a1b3eb008e4751 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:06:42 +0100 Subject: [PATCH 16/55] the Varible was being access from the TDZ --- Sprint-1/2-mandatory-errors/2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..7ee6ad0c18 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,10 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? + console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +/* The error is that the variable `cityOfBirth` is being used before it is declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement:*/ +//The variable were being accessed from the Temporal Dead Zone (TDZ) before it was declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement: + + From 9dad574a442fab085481d56b6daa1d910bcbcbbd Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:08:00 +0100 Subject: [PATCH 17/55] the varible has been hoisted and initialled before accessing --- Sprint-1/2-mandatory-errors/2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 7ee6ad0c18..7147af6f8f 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -7,4 +7,6 @@ const cityOfBirth = "Bolton"; /* The error is that the variable `cityOfBirth` is being used before it is declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement:*/ //The variable were being accessed from the Temporal Dead Zone (TDZ) before it was declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement: +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file From 94df8506897786912fefc2306482986c696134de Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:10:26 +0100 Subject: [PATCH 18/55] commenting out the first code to avoid SyntaxError --- Sprint-1/2-mandatory-errors/2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 7147af6f8f..2401f6c4c1 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,8 +2,8 @@ // what's the error ? -console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; +/*console.log(`I was born in ${cityOfBirth}`); +const cityOfBirth = "Bolton";*/ /* The error is that the variable `cityOfBirth` is being used before it is declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement:*/ //The variable were being accessed from the Temporal Dead Zone (TDZ) before it was declared and assigned a value. In JavaScript, variables declared with `const` (or `let`) are not hoisted in the same way as `var`, so you cannot access them before their declaration. To fix this, you should declare and assign the variable before using it in the `console.log` statement: From 26c75aaf824764416e2d4dea8d5e9e7954de5a9d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:35:58 +0100 Subject: [PATCH 19/55] I predicted that it wouldn't work as slice method is used on a number instead of string --- Sprint-1/2-mandatory-errors/3.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..6681506764 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,5 @@ const cardNumber = 4533787178994213; + const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +8,6 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value +// I suspect the code doesn't work because the slice method is being called on a number, but slice is a method for strings. Therefore, I predict that the code will throw an error saying that slice is not a function for numbers. + + From 7a6e15e5a54620f306824665b9b17d29c1ac3df3 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:41:30 +0100 Subject: [PATCH 20/55] I printed the type of data type variable cardNumber is on the console and it reads number, I have to comment out slice method line of code --- Sprint-1/2-mandatory-errors/3.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 6681506764..566c65991b 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,6 +1,7 @@ const cardNumber = 4533787178994213; +console.log(typeof cardNumber); -const last4Digits = cardNumber.slice(-4); +//const last4Digits = cardNumber.toString().slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -10,4 +11,6 @@ const last4Digits = cardNumber.slice(-4); // Then try updating the expression last4Digits is assigned to, in order to get the correct value // I suspect the code doesn't work because the slice method is being called on a number, but slice is a method for strings. Therefore, I predict that the code will throw an error saying that slice is not a function for numbers. +// i console the typeof cardNumber and it returns number + From e8a084e795ba5abc9ef814eec1868110163a98ee Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:46:09 +0100 Subject: [PATCH 21/55] commenting out the console.log(typeof cardNumber) before running the original code to see that error message says TypeError: cardNumber.slice is not a function --- Sprint-1/2-mandatory-errors/3.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 566c65991b..df81baf73a 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,7 +1,7 @@ const cardNumber = 4533787178994213; -console.log(typeof cardNumber); +//console.log(typeof cardNumber); -//const last4Digits = cardNumber.toString().slice(-4); +const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From 536afc35b7b71101b9391f5ebe3ab6faeaccd080 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:49:17 +0100 Subject: [PATCH 22/55] fixing the error my converting the number to string by putting double quotes around the numbers and printing last4Digits --- Sprint-1/2-mandatory-errors/3.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index df81baf73a..3c8b7b9288 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,7 +1,8 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; //console.log(typeof cardNumber); const last4Digits = cardNumber.slice(-4); +console.log(last4Digits); // Output: "4213" // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From aec02fcc9c8c4577e4cf0e49d8d41b50b1450344 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:57:29 +0100 Subject: [PATCH 23/55] Identifier cannot start with a number,must start with a leter , _ or $ so the the first varible was name was updated to start with doller sign --- Sprint-1/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..94a2356aa0 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const $12HourClockTime = "8:53pm"; +const _24hourClockTime = "20:53"; \ No newline at end of file From 224b857a10c67c2efbb4e0c6efb4c2953f796110 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 10:58:20 +0100 Subject: [PATCH 24/55] the second varible was updated to start with underscore --- Sprint-1/2-mandatory-errors/4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 94a2356aa0..66d5fa4064 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ const $12HourClockTime = "8:53pm"; -const _24hourClockTime = "20:53"; \ No newline at end of file +const _hourClockTime = "20:53"; \ No newline at end of file From fab2124fcd65d023a724735517fe606fa6c8cf32 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 21:43:43 +0100 Subject: [PATCH 25/55] added the missing comma to correct the error --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..bfa50e2027 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,"")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,9 +12,16 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made +// There are 5 function calls in this file. The function calls are made on the following lines: +// Line 1: replaceAll() +// Line 2: replaceAll() +// Line 5: Number() +// Line 6: Number() +// Line 9: console.log() -// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +// The error is occurring on line 5., and it's a SyntaxError: missing , The error is due to a missing comma in the replaceAll() method. The correct syntax should be replaceAll(",", ""). To fix this problem, we need to add the missing comma in the replaceAll() method on line 5 // c) Identify all the lines that are variable reassignment statements // d) Identify all the lines that are variable declarations From 018346610027cd418cd0127292c124e2194c2175 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 21:57:18 +0100 Subject: [PATCH 26/55] answered question on Variable reasignment lines --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index bfa50e2027..1e9b824b35 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -23,7 +23,12 @@ console.log(`The percentage change is ${percentageChange}`); // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? // The error is occurring on line 5., and it's a SyntaxError: missing , The error is due to a missing comma in the replaceAll() method. The correct syntax should be replaceAll(",", ""). To fix this problem, we need to add the missing comma in the replaceAll() method on line 5 // c) Identify all the lines that are variable reassignment statements +// The variable reassignment statements are on the following lines: +// Line 4: carPrice = Number(carPrice.replaceAll(",", "")); +// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,"")); // d) Identify all the lines that are variable declarations +// Line 1: let carPrice = "10,000"; +// Line 2: let priceAfterOneYear = "8,543"; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? From 69966b3d5048a26ad12bbe7b3541822920b8ca78 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 22:04:11 +0100 Subject: [PATCH 27/55] answered queation about variable declration --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 1e9b824b35..84d8fda05e 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -28,7 +28,13 @@ console.log(`The percentage change is ${percentageChange}`); // Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ,"")); // d) Identify all the lines that are variable declarations +// The variable declaration statements are on the following lines: // Line 1: let carPrice = "10,000"; // Line 2: let priceAfterOneYear = "8,543"; +// Line 7: const priceDifference = carPrice - priceAfterOneYear; +// Line 8: const percentageChange = (priceDifference / carPrice) * 100; +// A declaration is when a variable is created, using let or const. + + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? From 9a0c78806cfc4a9a06ac57d28dcb9f4ab294bd1f Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 20 Jun 2026 22:06:26 +0100 Subject: [PATCH 28/55] Answerd the question e about what the expression is doing --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 84d8fda05e..4e41414388 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -38,3 +38,4 @@ console.log(`The percentage change is ${percentageChange}`); // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +/* The expression Number(carPrice.replaceAll(",","")) is converting the string value of carPrice, which contains a comma, into a number. The replaceAll() method is used to remove all commas from the string, and then the Number() function is used to convert the resulting string into a number. This allows for mathematical operations to be performed on the value of carPrice without any issues caused by the presence of commas in the string.*/ From cb291d00f297bf2124513c8bcd5aca54a9a9971d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 05:31:22 +0100 Subject: [PATCH 29/55] Answered question on how many variable delaration are in the file --- Sprint-1/3-mandatory-interpret/2-time-format.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..6c67b3ce67 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,6 +12,14 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// There are 6 variable declarations in this program. The variable declarations are on the following lines: +// Line 1: const movieLength = 8784; +// Line 3: const remainingSeconds = movieLength % 60; +// Line 4: const totalMinutes = (movieLength - remainingSeconds) / 60; +// Line 6: const remainingMinutes = totalMinutes % 60; +// Line 7: const totalHours = (totalMinutes - remainingMinutes) / 60; +// Line 9: const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; + // b) How many function calls are there? From 0eada55e4c7bf4cec773be1c18b4b47bacce9676 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 05:35:05 +0100 Subject: [PATCH 30/55] Answered question on how many function calls are in the program --- Sprint-1/3-mandatory-interpret/2-time-format.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 6c67b3ce67..9dfaf7efc4 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -22,6 +22,9 @@ console.log(result); // b) How many function calls are there? +// There is 1 function call in this program. The function call is made on the following line: +// Line 10: console.log(result); + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators From 5d2e5f944349030e2334e13ecb63ced501c44b8a Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 05:38:13 +0100 Subject: [PATCH 31/55] Answered question on modulo Operation --- Sprint-1/3-mandatory-interpret/2-time-format.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 9dfaf7efc4..85cf91c141 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -27,6 +27,8 @@ console.log(result); // c) Using documentation, explain what the expression movieLength % 60 represents +// The expression movieLength % 60 represents the remainder of the division of movieLength by 60. In this case, it calculates the number of seconds remaining after converting the total length of the movie (in seconds) into minutes. The modulo operator (%) is used to find the remainder when one number is divided by another. So, if movieLength is 8784 seconds, movieLength % 60 will give us the number of seconds that do not make up a full minute. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? From 9a422afa0773c0c6745f6f749f8c1c6461ebd01d Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 05:44:02 +0100 Subject: [PATCH 32/55] Answered question on what line 4 is doing --- Sprint-1/3-mandatory-interpret/2-time-format.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 85cf91c141..64bee464a4 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -32,6 +32,7 @@ console.log(result); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression assigned to totalMinutes calculates the total number of minutes in the movie length. It does this by first subtracting the remaining seconds (calculated in line 3) from the total movie length (movieLength), which gives us the total number of seconds that can be fully converted into minutes. Then, it divides that result by 60 to convert those seconds into minutes. This gives us the total number of complete minutes in the movie length, excluding any remaining seconds. // e) What do you think the variable result represents? Can you think of a better name for this variable? From 0d1fd0499c259440a30dc09ea6337e71f56cbc9c Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 05:51:05 +0100 Subject: [PATCH 33/55] Answered question on what the varible result represents and the better name for the variable --- Sprint-1/3-mandatory-interpret/2-time-format.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 64bee464a4..cd294b79c5 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -35,5 +35,6 @@ console.log(result); // The expression assigned to totalMinutes calculates the total number of minutes in the movie length. It does this by first subtracting the remaining seconds (calculated in line 3) from the total movie length (movieLength), which gives us the total number of seconds that can be fully converted into minutes. Then, it divides that result by 60 to convert those seconds into minutes. This gives us the total number of complete minutes in the movie length, excluding any remaining seconds. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents the formatted string that shows the total length of the movie in hours, minutes, and seconds. A better name for this variable could be "formattedMovieLength" or "movieDuration" to more clearly indicate that it holds the duration of the movie in a human-readable format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer From b1a87d468e6d1b6e4b0afc52bc791b82e5c19945 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 06:09:02 +0100 Subject: [PATCH 34/55] Answered question about if the code will work for all values --- Sprint-1/3-mandatory-interpret/2-time-format.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index cd294b79c5..7af2bb9c58 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -38,3 +38,6 @@ console.log(result); // The variable result represents the formatted string that shows the total length of the movie in hours, minutes, and seconds. A better name for this variable could be "formattedMovieLength" or "movieDuration" to more clearly indicate that it holds the duration of the movie in a human-readable format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +/* The code will work for all non-negative integer values of movieLength, as it correctly calculates the hours, minutes, and seconds for any given length of time in seconds. However, if movieLength is a negative number or a non-integer value, the code may not produce meaningful results. For example, if movieLength is negative, the calculations for remainingSeconds, totalMinutes, and totalHours will not make sense in the context of a movie duration. Additionally, if movieLength is a non-integer (like a float), the calculations may yield unexpected results due to how JavaScript handles floating-point arithmetic. Therefore, it's best to ensure that movieLength is a non-negative integer for this code to work correctly. Also, it works correctly only when the movieleng is less than 24 hours, because the code does not account for days. If the movie length exceeds 24 hours, the totalHours variable will continue to increase without resetting after 24, which may not be the desired behavior for representing time in a standard format. */ +// if movieLength = 90000 seconds, that 25 hours , the variable result will be 25:0:0, which is not a standard representation of time. +// leading zeros , the variable result will always output resuls like H:M:S instead of HH:MM:SS, so if the movie length is 1 hour, 5 minutes and 9 seconds, the variable result will be 1:5:9 instead of 01:05:09. \ No newline at end of file From e6184ace4a361caf9d9e9644a14e6bdf83da6954 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 06:30:16 +0100 Subject: [PATCH 35/55] Describe the purpose and rational of step 2 --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..78e793b09f 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,4 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +//2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value From 9b3dbab00d6e2f13ba903afbf8906baef6963d7e Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 06:34:03 +0100 Subject: [PATCH 36/55] answered the purpose and rationale of line 8 --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 78e793b09f..48a230860a 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,4 +25,5 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" -//2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value +//2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value. +//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary. From ac91e9c470c9988fb038e8f88c7582f0a9635942 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 06:58:45 +0100 Subject: [PATCH 37/55] explains the .padStart method in context --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 48a230860a..e148bc42bb 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -26,4 +26,5 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" //2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value. -//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary. +//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary, .padStart(target Length, padString), adds strings to the start of the string until it reaches the target length, in this case 3, and if the string is already 3 or more characters long, it will not add any padding. + From cdf22c6f6023526f3cb9e001618eda62490a6294 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:10:21 +0100 Subject: [PATCH 38/55] explained the step 9 and it's rationale --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index e148bc42bb..e7c356a8ec 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -27,4 +27,5 @@ console.log(`£${pounds}.${pence}`); // 1. const penceString = "399p": initialises a string variable with the value "399p" //2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value. //3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary, .padStart(target Length, padString), adds strings to the start of the string until it reaches the target length, in this case 3, and if the string is already 3 or more characters long, it will not add any padding. +/*4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the price ,paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(0, 1) = "3" it took characters from index 0 to 1*/ From 564b749d0f866faabfa79c9a81dee1a8a89444ff Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:14:20 +0100 Subject: [PATCH 39/55] answered question and rationale of line 14 code --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index e7c356a8ec..2d0acdf086 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -28,4 +28,5 @@ console.log(`£${pounds}.${pence}`); //2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the pence string to isolate the numeric value. //3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures that the numeric value has at least three digits by padding with 3 leading zeros if necessary, .padStart(target Length, padString), adds strings to the start of the string until it reaches the target length, in this case 3, and if the string is already 3 or more characters long, it will not add any padding. /*4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the price ,paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(0, 1) = "3" it took characters from index 0 to 1*/ +/*5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion of the price and ensures it has two digits by padding with a trailing zero if necessary, paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(1) = "99" it took characters from index 1 to the end of the string, then .padEnd(2, "0") adds strings to the end of the string until it reaches the target length, in this case 2, and if the string is already 2 or more characters long, it will not add any padding.*/ From bb30402a00fbb9c4386a91b790a038a27606b66f Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:16:34 +0100 Subject: [PATCH 40/55] explained the purpose of line 18 and it's rational --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 2d0acdf086..086813fede 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -30,3 +30,5 @@ console.log(`£${pounds}.${pence}`); /*4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the price ,paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(0, 1) = "3" it took characters from index 0 to 1*/ /*5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion of the price and ensures it has two digits by padding with a trailing zero if necessary, paddedPenceNumberString.length =3, so paddedPenceNumberString.length - 2 = 1, so paddedPenceNumberString.substring(1) = "99" it took characters from index 1 to the end of the string, then .padEnd(2, "0") adds strings to the end of the string until it reaches the target length, in this case 2, and if the string is already 2 or more characters long, it will not add any padding.*/ +/*6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console, using template literals to insert the pounds and pence variables into the string. The output will be in the format "£X.YY", where X is the pounds value and YY is the pence value. In this case, it will output "£3.99".*/ + From 771b9ec893ea3d9b203412f5fd0a7900d7c55059 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:42:48 +0100 Subject: [PATCH 41/55] Answered question about invoking Alert for chrome.md file --- Sprint-1/4-stretch-explore/chrome.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..22bd92b2a2 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -10,7 +10,9 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; + What effect does calling the `alert` function have? +// By invoking alert("Hello world!"); the effect it has is that a small modal dialog box pops up at the top of the window browser displaying Hello world!, along with an OK button. Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. From 56ee0b7440c50d2163be5744baad8335027d42d5 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:55:01 +0100 Subject: [PATCH 42/55] Answered question on the effect of prompt function in chrome.md file --- Sprint-1/4-stretch-explore/chrome.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index 22bd92b2a2..8133bd55b6 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -17,4 +17,6 @@ What effect does calling the `alert` function have? Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? +//The effect is similar to the alert one a small modal dialog box pops up with the addition of a text input field and two buttons for 'OK' and 'Cancel', it displays the question What is your name? What is the return value of `prompt`? +//The return value of the 'prompt' depends on what action the client did , whci is one of two things based on the client actions.it will return whatever the client typed into the text field as string and click 'OK' and this will be stored in the variable myName, and can be verified by typing myName into the console and hitting ENTER.However if the user clicks cancel , it returns null. From 68c6a1f759a97f651cd05d1eeb63d5064971ae95 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 07:57:58 +0100 Subject: [PATCH 43/55] Answered question about console.log on object.md file --- Sprint-1/4-stretch-explore/objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..b06c411ab1 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -4,7 +4,7 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter -What output do you get? +What output do you get? // I got 'console.log' Now enter just `console` in the Console, what output do you get back? From 5720fea11261d232cba2b6bf71b5d366e345b8e2 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 08:05:53 +0100 Subject: [PATCH 44/55] updated the right ouput for console.log --- Sprint-1/4-stretch-explore/objects.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index b06c411ab1..381bf10192 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,6 +5,7 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? // I got 'console.log' +// ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? From 5a6e439d29006d03ec3c05e4a06c47727f22c592 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 08:08:47 +0100 Subject: [PATCH 45/55] answered question of the output of console in the consoledevtool --- Sprint-1/4-stretch-explore/objects.md | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 381bf10192..7956213c23 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -8,6 +8,85 @@ What output do you get? // I got 'console.log' // ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? +/*console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +assert +: +ƒ assert() +clear +: +ƒ clear() +context +: +ƒ context() +count +: +ƒ count() +countReset +: +ƒ countReset() +createTask +: +ƒ createTask() +debug +: +ƒ debug() +dir +: +ƒ dir() +dirxml +: +ƒ dirxml() +error +: +(...n)=> {…} +group +: +ƒ group() +groupCollapsed +: +ƒ groupCollapsed() +groupEnd +: +ƒ groupEnd() +info +: +ƒ info() +log +: +ƒ log() +memory +: +MemoryInfo {totalJSHeapSize: 33100000, usedJSHeapSize: 29400000, jsHeapSizeLimit: 3760000000} +profile +: +ƒ profile() +profileEnd +: +ƒ profileEnd() +table +: +ƒ table() +time +: +ƒ time() +timeEnd +: +ƒ timeEnd() +timeLog +: +ƒ timeLog() +timeStamp +: +ƒ timeStamp() +trace +: +(...n)=> {…} +warn +: +(...n)=> {…} +Symbol(Symbol.toStringTag) +: +"console"*/ Try also entering `typeof console` From 345ae8e9c1921a078b4721cfd85d851e2df9b9be Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 08:12:03 +0100 Subject: [PATCH 46/55] Answered question what I got when typed typeof console in Devtool console for Object.md file --- Sprint-1/4-stretch-explore/objects.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 7956213c23..da72cf69c3 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -89,6 +89,7 @@ Symbol(Symbol.toStringTag) "console"*/ Try also entering `typeof console` +// got: object Answer the following questions: From 9bd92150c221296b88be00f59a1d251c8623c8a8 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 08:18:09 +0100 Subject: [PATCH 47/55] Answered question about what console stores in Object.md file --- Sprint-1/4-stretch-explore/objects.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index da72cf69c3..d840e6e963 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -94,4 +94,5 @@ Try also entering `typeof console` Answer the following questions: What does `console` store? +/* Console is a globally available Object provided by the browser environment to store debugging tools functions in one convienient place*/ What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? From 9460b090ce429339c9f598020cc1a0ff84692a44 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 21 Jun 2026 08:33:31 +0100 Subject: [PATCH 48/55] answered the question about console.log and console.assert in object.md file --- Sprint-1/4-stretch-explore/objects.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index d840e6e963..a2119b424f 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -96,3 +96,4 @@ Answer the following questions: What does `console` store? /* Console is a globally available Object provided by the browser environment to store debugging tools functions in one convienient place*/ What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +/*`console.log` or `console.assert` mean? i.e console.log go inside the console Object and print out whatever you have on the console to see, log() is a method which does the action on the object , and for console.assert means check whether something is true and if it's not true show the error message on the console. the '.' is called the property accessor or dot Notation and what it does is to dig inside an object and grab a specific piece of data or functionality stored within it.*/ From e8730e3f7018876296f641fa320f8ccb8384ddde Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:28:05 +0100 Subject: [PATCH 49/55] Removed the double quote on the variable cardNuber value to make the value a number data type --- Sprint-1/2-mandatory-errors/3.js | 2 +- Sprint-2-backup/1-key-errors/0.js | 37 +++++++++++++++++ Sprint-2-backup/1-key-errors/1.js | 36 ++++++++++++++++ Sprint-2-backup/1-key-errors/2.js | 20 +++++++++ Sprint-2-backup/2-mandatory-debug/0.js | 14 +++++++ Sprint-2-backup/2-mandatory-debug/1.js | 13 ++++++ Sprint-2-backup/2-mandatory-debug/2.js | 24 +++++++++++ .../3-mandatory-implement/1-bmi.js | 19 +++++++++ .../3-mandatory-implement/2-cases.js | 16 ++++++++ .../3-mandatory-implement/3-to-pounds.js | 6 +++ .../4-mandatory-interpret/time-format.js | 38 +++++++++++++++++ .../5-stretch-extend/format-time.js | 25 +++++++++++ Sprint-2-backup/readme.md | 41 +++++++++++++++++++ 13 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 Sprint-2-backup/1-key-errors/0.js create mode 100644 Sprint-2-backup/1-key-errors/1.js create mode 100644 Sprint-2-backup/1-key-errors/2.js create mode 100644 Sprint-2-backup/2-mandatory-debug/0.js create mode 100644 Sprint-2-backup/2-mandatory-debug/1.js create mode 100644 Sprint-2-backup/2-mandatory-debug/2.js create mode 100644 Sprint-2-backup/3-mandatory-implement/1-bmi.js create mode 100644 Sprint-2-backup/3-mandatory-implement/2-cases.js create mode 100644 Sprint-2-backup/3-mandatory-implement/3-to-pounds.js create mode 100644 Sprint-2-backup/4-mandatory-interpret/time-format.js create mode 100644 Sprint-2-backup/5-stretch-extend/format-time.js create mode 100644 Sprint-2-backup/readme.md diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 3c8b7b9288..d97d1681ff 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = "4533787178994213"; +const cardNumber = 4533787178994213; //console.log(typeof cardNumber); const last4Digits = cardNumber.slice(-4); diff --git a/Sprint-2-backup/1-key-errors/0.js b/Sprint-2-backup/1-key-errors/0.js new file mode 100644 index 0000000000..608db1a8be --- /dev/null +++ b/Sprint-2-backup/1-key-errors/0.js @@ -0,0 +1,37 @@ +// Predict and explain first... /*There will be a syntax error in the code because the variable `str` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'str' has already been declared" error.*? +// =============> write your prediction here // there will be an error message as such SyntaxError: Identifier 'str' has already been declared + +// call the function capitalise with a string input// capitalise("tobias"); +// interpret the error message and figure out why an error is occurring, /* + +/*function capitalise(str) { + let str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +}*/ +// =============> write your explanation here + + +/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 + let str = `${str[0].toUpperCase()}${str.slice(1)}`; + ^ + +SyntaxError: Identifier 'str' has already been declared + at Object.compileFunction (node:vm:353:18) + at wrapSafe (node:internal/modules/cjs/loader:1039:15) + at Module._compile (node:internal/modules/cjs/loader:1073:27) + at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) + at Module.load (node:internal/modules/cjs/loader:989:32) + at Function.Module._load (node:internal/modules/cjs/loader:829:14) + at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) + at node:internal/main/run_main_module:17:47*/ + // from the error message above the error occurred at line 8 where the variable `str` was declared again using `let` inside the function body, which is not allowed since `str` was already declared as a parameter of the function. + // to fix this error, we can either rename the variable inside the function body or remove the `let` keyword and just assign a new value to `str` without redeclaring it. + + // =============> write your new code here + function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; + } + capitalise("tobias"); + console.log(capitalise("tobias")); // Output: "Tobias" + \ No newline at end of file diff --git a/Sprint-2-backup/1-key-errors/1.js b/Sprint-2-backup/1-key-errors/1.js new file mode 100644 index 0000000000..73827ecc86 --- /dev/null +++ b/Sprint-2-backup/1-key-errors/1.js @@ -0,0 +1,36 @@ +// Predict and explain first... +/* There will be a syntax error in the code because the variable `decimalNumber` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'decimalNumber' has already been declared" error. secondly variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope.*/ + +// Why will an error occur when this program runs?/* The variable 'decimalNumber ' is being redeclared inside the function, which is not allowed since it was already declared as a parameter of the function. And the variable `decimalNumber` is being logged to the console outside of the function, which will cause a ReferenceError since `decimalNumber` is not defined in that scope.*/ +// =============> write your prediction here. // This will cause a syntax error, additionally also cause a reference error since the variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope. + + +// Try playing computer with the example to work out what is going on + +function convertToPercentage(decimalNumber) { + const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(decimalNumber); + +// =============> write your explanation here + +// Finally, correct the code to fix the problem +// =============> write your new code here + +/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:11 + const decimalNumber = 0.5; + ^ + +SyntaxError: Identifier 'decimalNumber' has already been declared + at Object.compileFunction (node:vm:353:18) + at wrapSafe (node:internal/modules/cjs/loader:1039:15) + at Module._compile (node:internal/modules/cjs/loader:1073:27) + at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) + at Module.load (node:internal/modules/cjs/loader:989:32) + at Function.Module._load (node:internal/modules/cjs/loader:829:14) + at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) + at node:internal/main/run_main_module:17:47*/ \ No newline at end of file diff --git a/Sprint-2-backup/1-key-errors/2.js b/Sprint-2-backup/1-key-errors/2.js new file mode 100644 index 0000000000..aad57f7cfe --- /dev/null +++ b/Sprint-2-backup/1-key-errors/2.js @@ -0,0 +1,20 @@ + +// Predict and explain first BEFORE you run any code... + +// this function should square any number but instead we're going to get an error + +// =============> write your prediction of the error here + +function square(3) { + return num * num; +} + +// =============> write the error message here + +// =============> explain this error message here + +// Finally, correct the code to fix the problem + +// =============> write your new code here + + diff --git a/Sprint-2-backup/2-mandatory-debug/0.js b/Sprint-2-backup/2-mandatory-debug/0.js new file mode 100644 index 0000000000..b27511b417 --- /dev/null +++ b/Sprint-2-backup/2-mandatory-debug/0.js @@ -0,0 +1,14 @@ +// Predict and explain first... + +// =============> write your prediction here + +function multiply(a, b) { + console.log(a * b); +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +// =============> write your explanation here + +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2-backup/2-mandatory-debug/1.js b/Sprint-2-backup/2-mandatory-debug/1.js new file mode 100644 index 0000000000..37cedfbcfd --- /dev/null +++ b/Sprint-2-backup/2-mandatory-debug/1.js @@ -0,0 +1,13 @@ +// Predict and explain first... +// =============> write your prediction here + +function sum(a, b) { + return; + a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// =============> write your explanation here +// Finally, correct the code to fix the problem +// =============> write your new code here diff --git a/Sprint-2-backup/2-mandatory-debug/2.js b/Sprint-2-backup/2-mandatory-debug/2.js new file mode 100644 index 0000000000..57d3f5dc35 --- /dev/null +++ b/Sprint-2-backup/2-mandatory-debug/2.js @@ -0,0 +1,24 @@ +// Predict and explain first... + +// Predict the output of the following code: +// =============> Write your prediction here + +const num = 103; + +function getLastDigit() { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + +// Now run the code and compare the output to your prediction +// =============> write the output here +// Explain why the output is the way it is +// =============> write your explanation here +// Finally, correct the code to fix the problem +// =============> write your new code here + +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem diff --git a/Sprint-2-backup/3-mandatory-implement/1-bmi.js b/Sprint-2-backup/3-mandatory-implement/1-bmi.js new file mode 100644 index 0000000000..17b1cbde1b --- /dev/null +++ b/Sprint-2-backup/3-mandatory-implement/1-bmi.js @@ -0,0 +1,19 @@ +// Below are the steps for how BMI is calculated + +// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. + +// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: + +// squaring your height: 1.73 x 1.73 = 2.99 +// dividing 70 by 2.99 = 23.41 +// Your result will be displayed to 1 decimal place, for example 23.4. + +// You will need to implement a function that calculates the BMI of someone based off their weight and height + +// Given someone's weight in kg and height in metres +// Then when we call this function with the weight and height +// It should return their Body Mass Index to 1 decimal place + +function calculateBMI(weight, height) { + // return the BMI of someone based off their weight and height +} \ No newline at end of file diff --git a/Sprint-2-backup/3-mandatory-implement/2-cases.js b/Sprint-2-backup/3-mandatory-implement/2-cases.js new file mode 100644 index 0000000000..5b0ef77ad9 --- /dev/null +++ b/Sprint-2-backup/3-mandatory-implement/2-cases.js @@ -0,0 +1,16 @@ +// A set of words can be grouped together in different cases. + +// For example, "hello there" in snake case would be written "hello_there" +// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. + +// Implement a function that: + +// Given a string input like "hello there" +// When we call this function with the input string +// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" + +// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" + +// You will need to come up with an appropriate name for the function +// Use the MDN string documentation to help you find a solution +// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase diff --git a/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js b/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js new file mode 100644 index 0000000000..6265a1a703 --- /dev/null +++ b/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js @@ -0,0 +1,6 @@ +// In Sprint-1, there is a program written in interpret/to-pounds.js + +// You will need to take this code and turn it into a reusable block of code. +// You will need to declare a function called toPounds with an appropriately named parameter. + +// You should call this function a number of times to check it works for different inputs diff --git a/Sprint-2-backup/4-mandatory-interpret/time-format.js b/Sprint-2-backup/4-mandatory-interpret/time-format.js new file mode 100644 index 0000000000..17127bc01e --- /dev/null +++ b/Sprint-2-backup/4-mandatory-interpret/time-format.js @@ -0,0 +1,38 @@ +function pad(num) { + let numString = num.toString(); + while (numString.length < 2) { + numString = "0" + numString; + } + return numString; +} + +function formatTimeDisplay(seconds) { + const remainingSeconds = seconds % 60; + const totalMinutes = (seconds - remainingSeconds) / 60; + const remainingMinutes = totalMinutes % 60; + const totalHours = (totalMinutes - remainingMinutes) / 60; + + return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; +} + +// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit +// to help you answer these questions + +// Questions + +// a) When formatTimeDisplay is called how many times will pad be called? +// =============> write your answer here + +// Call formatTimeDisplay with an input of 61, now answer the following: + +// b) What is the value assigned to num when pad is called for the first time? +// =============> write your answer here + +// c) What is the return value of pad is called for the first time? +// =============> write your answer here + +// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer +// =============> write your answer here + +// e) What is the return value of pad when it is called for the last time in this program? Explain your answer +// =============> write your answer here diff --git a/Sprint-2-backup/5-stretch-extend/format-time.js b/Sprint-2-backup/5-stretch-extend/format-time.js new file mode 100644 index 0000000000..32a32e66b8 --- /dev/null +++ b/Sprint-2-backup/5-stretch-extend/format-time.js @@ -0,0 +1,25 @@ +// This is the latest solution to the problem from the prep. +// Make sure to do the prep before you do the coursework +// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. + +function formatAs12HourClock(time) { + const hours = Number(time.slice(0, 2)); + if (hours > 12) { + return `${hours - 12}:00 pm`; + } + return `${time} am`; +} + +const currentOutput = formatAs12HourClock("08:00"); +const targetOutput = "08:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); + +const currentOutput2 = formatAs12HourClock("23:00"); +const targetOutput2 = "11:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); diff --git a/Sprint-2-backup/readme.md b/Sprint-2-backup/readme.md new file mode 100644 index 0000000000..44c118e338 --- /dev/null +++ b/Sprint-2-backup/readme.md @@ -0,0 +1,41 @@ +# 🧭 Guide to week 2 exercises + +> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ + +> [!TIP] +> You should always do the prep work _before_ attempting the coursework. +> The prep shows you how to do the coursework. +> There is often a step by step video you can code along with too. +> Do the prep. + +## 1 Errors + +In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. + +## 2 Debug + +In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too. + +## 3 Implement + +In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs. + +Here is a recommended order: + +1. `1-bmi.js` +1. `2-cases.js` +1. `3-to-pounds.js` + +## 4 Interpret + +In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. + +You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! + +You can also use `console.log` to check the value of different variables in the code. + +## 5 Extend + +In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. + +Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. This section is not mandatory, but it will also help you solve some similar kata in Codewars. From cd370905c4aca3e86d762f916235663708910b90 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:32:01 +0100 Subject: [PATCH 50/55] used .toString to cast the nuber date type to string and assign the value to cardNumberString --- Sprint-1/2-mandatory-errors/3.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index d97d1681ff..70269bcf71 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; //console.log(typeof cardNumber); +const cardNumberString = cardNumber.toString(); const last4Digits = cardNumber.slice(-4); console.log(last4Digits); // Output: "4213" From 28eeec90c230ff09fbcedea981aca12f3b63e1de Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:34:32 +0100 Subject: [PATCH 51/55] used .slice to extrat the last 4 digits from the cardNumberString --- Sprint-1/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 70269bcf71..6e75f8fa6b 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -2,7 +2,7 @@ const cardNumber = 4533787178994213; //console.log(typeof cardNumber); const cardNumberString = cardNumber.toString(); -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumberString.slice(-4); console.log(last4Digits); // Output: "4213" // The last4Digits variable should store the last 4 digits of cardNumber From 7ad39551e2ccb41d16ba3aa9fa6afa9e393cde1a Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:38:06 +0100 Subject: [PATCH 52/55] used the correct javascript naming convention for the first variable --- Sprint-1/2-mandatory-errors/4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 66d5fa4064..cebc32f024 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const $12HourClockTime = "8:53pm"; +const twelveHourClockTime = "8:53pm"; const _hourClockTime = "20:53"; \ No newline at end of file From 76151fde40ed93c87e8eced1b0297f9ad5bbaf30 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:39:44 +0100 Subject: [PATCH 53/55] used best practices naming convention to rename the second variable --- Sprint-1/2-mandatory-errors/4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index cebc32f024..52517b0dc9 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ const twelveHourClockTime = "8:53pm"; -const _hourClockTime = "20:53"; \ No newline at end of file +const twentyFourHourClockTime = "20:53"; \ No newline at end of file From a96b47edea6a7784209709b94b8a9e8fd07d6391 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 17:48:30 +0100 Subject: [PATCH 54/55] gave the right programming term for the term that belongs in the blank --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 4e41414388..1691f31938 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -39,3 +39,4 @@ console.log(`The percentage change is ${percentageChange}`); // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? /* The expression Number(carPrice.replaceAll(",","")) is converting the string value of carPrice, which contains a comma, into a number. The replaceAll() method is used to remove all commas from the string, and then the Number() function is used to convert the resulting string into a number. This allows for mathematical operations to be performed on the value of carPrice without any issues caused by the presence of commas in the string.*/ +// a comma is missing between the two arguments in the replaceAll() method, which is causing a syntax error. The correct syntax should be replaceAll(",", "")., the programming term that belongs in the blank is call Arguments as they are actual values passed when the function is called: From 0dd852d235d63c222ab87d580c4479d89cd503c8 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Jun 2026 18:22:57 +0100 Subject: [PATCH 55/55] Remove Sprint-2-backup files - this PR is for Sprint-1 only --- Sprint-2-backup/1-key-errors/0.js | 37 ----------------- Sprint-2-backup/1-key-errors/1.js | 36 ---------------- Sprint-2-backup/1-key-errors/2.js | 20 --------- Sprint-2-backup/2-mandatory-debug/0.js | 14 ------- Sprint-2-backup/2-mandatory-debug/1.js | 13 ------ Sprint-2-backup/2-mandatory-debug/2.js | 24 ----------- .../3-mandatory-implement/1-bmi.js | 19 --------- .../3-mandatory-implement/2-cases.js | 16 -------- .../3-mandatory-implement/3-to-pounds.js | 6 --- .../4-mandatory-interpret/time-format.js | 38 ----------------- .../5-stretch-extend/format-time.js | 25 ----------- Sprint-2-backup/readme.md | 41 ------------------- 12 files changed, 289 deletions(-) delete mode 100644 Sprint-2-backup/1-key-errors/0.js delete mode 100644 Sprint-2-backup/1-key-errors/1.js delete mode 100644 Sprint-2-backup/1-key-errors/2.js delete mode 100644 Sprint-2-backup/2-mandatory-debug/0.js delete mode 100644 Sprint-2-backup/2-mandatory-debug/1.js delete mode 100644 Sprint-2-backup/2-mandatory-debug/2.js delete mode 100644 Sprint-2-backup/3-mandatory-implement/1-bmi.js delete mode 100644 Sprint-2-backup/3-mandatory-implement/2-cases.js delete mode 100644 Sprint-2-backup/3-mandatory-implement/3-to-pounds.js delete mode 100644 Sprint-2-backup/4-mandatory-interpret/time-format.js delete mode 100644 Sprint-2-backup/5-stretch-extend/format-time.js delete mode 100644 Sprint-2-backup/readme.md diff --git a/Sprint-2-backup/1-key-errors/0.js b/Sprint-2-backup/1-key-errors/0.js deleted file mode 100644 index 608db1a8be..0000000000 --- a/Sprint-2-backup/1-key-errors/0.js +++ /dev/null @@ -1,37 +0,0 @@ -// Predict and explain first... /*There will be a syntax error in the code because the variable `str` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'str' has already been declared" error.*? -// =============> write your prediction here // there will be an error message as such SyntaxError: Identifier 'str' has already been declared - -// call the function capitalise with a string input// capitalise("tobias"); -// interpret the error message and figure out why an error is occurring, /* - -/*function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -}*/ -// =============> write your explanation here - - -/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - ^ - -SyntaxError: Identifier 'str' has already been declared - at Object.compileFunction (node:vm:353:18) - at wrapSafe (node:internal/modules/cjs/loader:1039:15) - at Module._compile (node:internal/modules/cjs/loader:1073:27) - at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) - at Module.load (node:internal/modules/cjs/loader:989:32) - at Function.Module._load (node:internal/modules/cjs/loader:829:14) - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) - at node:internal/main/run_main_module:17:47*/ - // from the error message above the error occurred at line 8 where the variable `str` was declared again using `let` inside the function body, which is not allowed since `str` was already declared as a parameter of the function. - // to fix this error, we can either rename the variable inside the function body or remove the `let` keyword and just assign a new value to `str` without redeclaring it. - - // =============> write your new code here - function capitalise(str) { - str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; - } - capitalise("tobias"); - console.log(capitalise("tobias")); // Output: "Tobias" - \ No newline at end of file diff --git a/Sprint-2-backup/1-key-errors/1.js b/Sprint-2-backup/1-key-errors/1.js deleted file mode 100644 index 73827ecc86..0000000000 --- a/Sprint-2-backup/1-key-errors/1.js +++ /dev/null @@ -1,36 +0,0 @@ -// Predict and explain first... -/* There will be a syntax error in the code because the variable `decimalNumber` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'decimalNumber' has already been declared" error. secondly variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope.*/ - -// Why will an error occur when this program runs?/* The variable 'decimalNumber ' is being redeclared inside the function, which is not allowed since it was already declared as a parameter of the function. And the variable `decimalNumber` is being logged to the console outside of the function, which will cause a ReferenceError since `decimalNumber` is not defined in that scope.*/ -// =============> write your prediction here. // This will cause a syntax error, additionally also cause a reference error since the variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope. - - -// Try playing computer with the example to work out what is going on - -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - - return percentage; -} - -console.log(decimalNumber); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here - -/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:11 - const decimalNumber = 0.5; - ^ - -SyntaxError: Identifier 'decimalNumber' has already been declared - at Object.compileFunction (node:vm:353:18) - at wrapSafe (node:internal/modules/cjs/loader:1039:15) - at Module._compile (node:internal/modules/cjs/loader:1073:27) - at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) - at Module.load (node:internal/modules/cjs/loader:989:32) - at Function.Module._load (node:internal/modules/cjs/loader:829:14) - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) - at node:internal/main/run_main_module:17:47*/ \ No newline at end of file diff --git a/Sprint-2-backup/1-key-errors/2.js b/Sprint-2-backup/1-key-errors/2.js deleted file mode 100644 index aad57f7cfe..0000000000 --- a/Sprint-2-backup/1-key-errors/2.js +++ /dev/null @@ -1,20 +0,0 @@ - -// Predict and explain first BEFORE you run any code... - -// this function should square any number but instead we're going to get an error - -// =============> write your prediction of the error here - -function square(3) { - return num * num; -} - -// =============> write the error message here - -// =============> explain this error message here - -// Finally, correct the code to fix the problem - -// =============> write your new code here - - diff --git a/Sprint-2-backup/2-mandatory-debug/0.js b/Sprint-2-backup/2-mandatory-debug/0.js deleted file mode 100644 index b27511b417..0000000000 --- a/Sprint-2-backup/2-mandatory-debug/0.js +++ /dev/null @@ -1,14 +0,0 @@ -// Predict and explain first... - -// =============> write your prediction here - -function multiply(a, b) { - console.log(a * b); -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2-backup/2-mandatory-debug/1.js b/Sprint-2-backup/2-mandatory-debug/1.js deleted file mode 100644 index 37cedfbcfd..0000000000 --- a/Sprint-2-backup/2-mandatory-debug/1.js +++ /dev/null @@ -1,13 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2-backup/2-mandatory-debug/2.js b/Sprint-2-backup/2-mandatory-debug/2.js deleted file mode 100644 index 57d3f5dc35..0000000000 --- a/Sprint-2-backup/2-mandatory-debug/2.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first... - -// Predict the output of the following code: -// =============> Write your prediction here - -const num = 103; - -function getLastDigit() { - return num.toString().slice(-1); -} - -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); - -// Now run the code and compare the output to your prediction -// =============> write the output here -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - -// This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem diff --git a/Sprint-2-backup/3-mandatory-implement/1-bmi.js b/Sprint-2-backup/3-mandatory-implement/1-bmi.js deleted file mode 100644 index 17b1cbde1b..0000000000 --- a/Sprint-2-backup/3-mandatory-implement/1-bmi.js +++ /dev/null @@ -1,19 +0,0 @@ -// Below are the steps for how BMI is calculated - -// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. - -// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: - -// squaring your height: 1.73 x 1.73 = 2.99 -// dividing 70 by 2.99 = 23.41 -// Your result will be displayed to 1 decimal place, for example 23.4. - -// You will need to implement a function that calculates the BMI of someone based off their weight and height - -// Given someone's weight in kg and height in metres -// Then when we call this function with the weight and height -// It should return their Body Mass Index to 1 decimal place - -function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file diff --git a/Sprint-2-backup/3-mandatory-implement/2-cases.js b/Sprint-2-backup/3-mandatory-implement/2-cases.js deleted file mode 100644 index 5b0ef77ad9..0000000000 --- a/Sprint-2-backup/3-mandatory-implement/2-cases.js +++ /dev/null @@ -1,16 +0,0 @@ -// A set of words can be grouped together in different cases. - -// For example, "hello there" in snake case would be written "hello_there" -// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. - -// Implement a function that: - -// Given a string input like "hello there" -// When we call this function with the input string -// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" - -// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" - -// You will need to come up with an appropriate name for the function -// Use the MDN string documentation to help you find a solution -// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase diff --git a/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js b/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js deleted file mode 100644 index 6265a1a703..0000000000 --- a/Sprint-2-backup/3-mandatory-implement/3-to-pounds.js +++ /dev/null @@ -1,6 +0,0 @@ -// In Sprint-1, there is a program written in interpret/to-pounds.js - -// You will need to take this code and turn it into a reusable block of code. -// You will need to declare a function called toPounds with an appropriately named parameter. - -// You should call this function a number of times to check it works for different inputs diff --git a/Sprint-2-backup/4-mandatory-interpret/time-format.js b/Sprint-2-backup/4-mandatory-interpret/time-format.js deleted file mode 100644 index 17127bc01e..0000000000 --- a/Sprint-2-backup/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,38 +0,0 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; -} - -// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit -// to help you answer these questions - -// Questions - -// a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here - -// Call formatTimeDisplay with an input of 61, now answer the following: - -// b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here - -// c) What is the return value of pad is called for the first time? -// =============> write your answer here - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here - -// e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here diff --git a/Sprint-2-backup/5-stretch-extend/format-time.js b/Sprint-2-backup/5-stretch-extend/format-time.js deleted file mode 100644 index 32a32e66b8..0000000000 --- a/Sprint-2-backup/5-stretch-extend/format-time.js +++ /dev/null @@ -1,25 +0,0 @@ -// This is the latest solution to the problem from the prep. -// Make sure to do the prep before you do the coursework -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. - -function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; -} - -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); diff --git a/Sprint-2-backup/readme.md b/Sprint-2-backup/readme.md deleted file mode 100644 index 44c118e338..0000000000 --- a/Sprint-2-backup/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -# 🧭 Guide to week 2 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -## 1 Errors - -In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. - -## 2 Debug - -In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too. - -## 3 Implement - -In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs. - -Here is a recommended order: - -1. `1-bmi.js` -1. `2-cases.js` -1. `3-to-pounds.js` - -## 4 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -## 5 Extend - -In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. - -Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. This section is not mandatory, but it will also help you solve some similar kata in Codewars.