From 9c565249eaddfa69f1764b0d70ab38dc7882d58c Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 16:07:02 +0200 Subject: [PATCH 01/28] add explanation for line 3 --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..226bae22f3 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +// line 3 increments count by 1 and reassigns updated value back to the count variable From 258c544aef7a9a3070d081900c478ed5fe41682c Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 16:24:22 +0200 Subject: [PATCH 02/28] add solution to initials,js --- Sprint-1/1-key-exercises/2-initials.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..52f0bd72f0 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,6 @@ 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 bb5f2a0392b01b2a7064f96c4dba9e55fe9b8281 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 17:09:14 +0200 Subject: [PATCH 03/28] add solution to paths.js --- Sprint-1/1-key-exercises/3-paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..769a04777f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From cb97a289773d80b48a9f7bbd96a5075b83ee5f11 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:56:36 +0200 Subject: [PATCH 04/28] add explanation and breaking down random.js --- Sprint-1/1-key-exercises/4-random.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..dec44ebe20 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,13 @@ 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 + +// Print the random number to the console +console.log(num); + +//num is a random whole number between 1 and 100. + +//Math.random() creates a random decimal. +//Multiply by the range size. +// Math.floor() rounds down. +// Add minimum so it starts at 1. From 82ee28e3d90b223f413c8850c945cd30b623b7e7 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:01:38 +0200 Subject: [PATCH 05/28] fix error multi line commenting --- 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..e9c7b03f21 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?*/ From 66b60ba0e36adc58d01258a79347612e2cca26e6 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:03:17 +0200 Subject: [PATCH 06/28] fix error by changing const to let --- Sprint-1/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..031839b47d 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 3d99c5dfe98e8d20b5bada3dcd7a2354c3cd3e10 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:06:28 +0200 Subject: [PATCH 07/28] fix error : declare constant first --- Sprint-1/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..2865eb8a42 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // 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"; +console.log(`I was born in ${cityOfBirth}`); From cc3622b18f585a1754b18484557bca1f54744128 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:45:57 +0200 Subject: [PATCH 08/28] explain and fix error 3 --- Sprint-1/2-mandatory-errors/3.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..66b49cc0e6 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ const cardNumber = 4533787178994213; -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 @@ -7,3 +7,10 @@ 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 predict the code will not work because cardNumber is a number and .slice() is used on strings (or arrays), not numbers. +//When you run it, JavaScript gives an error which is TypeError: cardNumber.slice is not a function +//the reason is because creates a number, and numbers do not have a .slice() method. +//the fix is converting the number to a string + +console.log(last4Digits); From e5269604c0d97bc29f7f22541d0ab2f1970ea513 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:49:29 +0200 Subject: [PATCH 09/28] fix invalid variable name --- Sprint-1/2-mandatory-errors/4.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..1c45f420ca 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; + +//the code will fail because variable names cannot start with a number From 8b6c551f9ff268a6c569996c949115c6afb4eaec Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:14:20 +0200 Subject: [PATCH 10/28] debugging errors --- .../1-percentage-change.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..47779cfa54 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -20,3 +20,30 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +//answers + +/* a) there are there three + carPrice.replaceAll(",", "") + Number(carPrice.replaceAll(",", "")) + Number(priceAfterOneYear.replaceAll(",", ""))*/ + +/* b) priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +The issue is a syntax mistake in the brackets/quotes, and JavaScript throws a SyntaxError before running. + +the fix would be priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + +*/ + +/* c)carPrice = Number(carPrice.replaceAll(",", "")); + priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));*/ + +/* d) let carPrice = "10,000"; +let priceAfterOneYear = "8,543"; +const priceDifference = carPrice - priceAfterOneYear; +const percentageChange = (priceDifference / carPrice) * 100;*/ + +/* e)carPrice is a string: + replaceAll(",", "") removes commas: + Number(...) converts string to a number: + Convert a formatted string number into a real numeric value so calculations can work.*/ From 40e7f61be4f8f31494c471ab93ca52197fb9b40f Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:32:15 +0200 Subject: [PATCH 11/28] answer questions --- .../3-mandatory-interpret/2-time-format.js | 21 +++++++++++++++++++ 1 file changed, 21 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..5814f9c992 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -13,13 +13,34 @@ console.log(result); // a) How many variable declarations are there in this program? +/* there are 6 variable declarations +const movieLength = 8784; +const remainingSeconds = movieLength % 60; +const totalMinutes = (movieLength - remainingSeconds) / 60; +const remainingMinutes = totalMinutes % 60; +const totalHours = (totalMinutes - remainingMinutes) / 60; +const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;*/ + // b) How many function calls are there? +/* there is one function call + 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 +//The % operator is called the modulus (remainder) operator. +//it means Divide movieLength by 60 and return the remainder // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//This means:Convert the total seconds into full minutes without the leftover seconds + // e) What do you think the variable result represents? Can you think of a better name for this variable? +//A time format (hours:minutes:seconds) for the movie length, a better name would be movieDuration + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +//No, it will not work perfectly for all values. +//It does not add leading zeros (so you get 2:5:7 instead of 02:05:07) +//The format can look wrong for some numbers From 6b61878491681c12dfaff7ac1ecbc3b658cb4d95 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:39:59 +0200 Subject: [PATCH 12/28] breakdown of each line --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..9c6bc8614e 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,20 +1,31 @@ +//Creates a string that represents a price in pence (with a “p” at the end). const penceString = "399p"; +/*Removes the last character "p" +So "399p" becomes "399".*/ const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1 ); +//Makes sure the number has at least 3 digits. +//If it's shorter, it adds leading zeros. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + +//Takes everything except the last 2 digits. +//This becomes the pounds part. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); +//Takes the last 2 digits as pence. +//If needed, it adds a trailing zero to make sure it always has 2 digits. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); +//Prints the final formatted price in pounds and pence format. console.log(`£${pounds}.${pence}`); // This program takes a string representing a price in pence From 015026077d765812d7e05ce293e6a7dfaf6f0e9f Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Fri, 19 Jun 2026 19:56:36 +0200 Subject: [PATCH 13/28] add console log --- Sprint-1/1-key-exercises/2-initials.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 52f0bd72f0..82f93573d3 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -7,4 +7,6 @@ let lastName = "Johnson"; let initials = `firstName[0]+middleName[0]+lastName[0]`; +console.log(initials); + // https://www.google.com/search?q=get+first+character+of+string+mdn From ee92c6cc16c058c73b0f2c51563eaad3e11bbe7b Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Fri, 19 Jun 2026 19:57:36 +0200 Subject: [PATCH 14/28] add console log --- 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 769a04777f..038a35066c 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -20,4 +20,7 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); +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 From d3c7750d6f147b81ce09fddaad5becec6c5a4fcc Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Fri, 19 Jun 2026 20:07:13 +0200 Subject: [PATCH 15/28] add more functions --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 7 +++++-- 1 file changed, 5 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 47779cfa54..ab5f87d288 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -23,10 +23,13 @@ console.log(`The percentage change is ${percentageChange}`); //answers -/* a) there are there three +/* a) there are there five carPrice.replaceAll(",", "") Number(carPrice.replaceAll(",", "")) - Number(priceAfterOneYear.replaceAll(",", ""))*/ + Number(priceAfterOneYear.replaceAll(",", "")) + console.log(...) - + (priceDifference / carPrice) * 100 - line 7 (this is an expression that involves division and multiplication, but it does not involve a function call)*/ + /* b) priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); The issue is a syntax mistake in the brackets/quotes, and JavaScript throws a SyntaxError before running. From e5de5121021e3dd00b89c599e46c4004df8b7763 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 22 Jun 2026 17:53:48 +0200 Subject: [PATCH 16/28] declare variables --- Sprint-1/1-key-exercises/2-initials.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 82f93573d3..fc0a806a73 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,8 +5,11 @@ 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 firstName = "Chris"; +let middleName = "Kevin"; +let lastName = "Jones"; -console.log(initials); +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From 07630564627963c85286b0f8861ca9d241af2c30 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Mon, 22 Jun 2026 18:05:22 +0200 Subject: [PATCH 17/28] deugging --- Sprint-1/1-key-exercises/3-paths.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 038a35066c..2a06cf8010 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,9 +17,30 @@ 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 filePath = "Documents/work/report.pdf"; + +const lastSlashIndex = filePath.lastIndexOf("/"); +const lastDotIndex = filePath.lastIndexOf("."); + const dir = filePath.slice(0, lastSlashIndex); const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); +console.log(dir); +console.log(ext); + +const lastSlashIndex = filePath.lastIndexOf("/"); +const lastDotIndex = filePath.lastIndexOf("."); + +// Store the directory +const dir = filePath.slice(0, lastSlashIndex); + +// Store the extension +const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); + +console.log(dir); +console.log(ext); +lastDotIndex; + console.log(`The dir part of ${filePath} is ${dir}`); console.log(`The ext part of ${filePath} is ${ext}`); From ee94a453b0658fa4e4ac5b8adf028b5439b2a67e Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 18:51:31 +0200 Subject: [PATCH 18/28] fix: correct capitalise function --- Sprint-2/1-key-errors/0.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..6bb32c6ec2 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,23 @@ // Predict and explain first... -// =============> write your prediction here +// =============> It should take a string and capitalise the first letter but i predict it will throw an // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +/*The error occurs because str is declared twice. The function already receives str as a parameter, and then let str tries to create another variable with the same name inside the same scope. JavaScript does not allow redeclaring a variable with let, so it throws an error.*/ + function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } // =============> write your explanation here + +/* This function takes a string and capitalise the first letter. It uses `str[0].toUpperCase()` to convert the first character to uppercase and `str.slice(1)` to get the rest of the word unchanged. The function then joins both parts together and returns the new string. When `console.log(capitalise("hello"), capitalise("world"))` is run, the function executes twice and prints `Hello World`. + */ + // =============> write your new code here +function capitalise(str) { + return (str = `${str[0].toUpperCase()}${str.slice(1)}`); +} +console.log(capitalise("hello"), capitalise("world")); From a6ba68a27b7330612a3c30c7594800f6a8689740 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:06:14 +0200 Subject: [PATCH 19/28] fix: correct convertToPercentage function --- Sprint-2/1-key-errors/1.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..04663032e2 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,5 +1,4 @@ // Predict and explain first... - // Why will an error occur when this program runs? // =============> write your prediction here @@ -16,5 +15,15 @@ console.log(decimalNumber); // =============> write your explanation here +/*An error will occur when the program runs because decimalNumber is declared twice. The function already receives decimalNumber as a parameter, but then const decimalNumber = 0.5 tries to create another variable with the same name inside the same scope. JavaScript does not allow redeclaring variables with const. +Another error will happen at console.log(decimalNumber) because decimalNumber only exists inside the function and cannot be accessed outside of it.*/ + // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); From 0a0529121848c3d63fe14e95b803bc01d71830e7 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:32:33 +0200 Subject: [PATCH 20/28] fix: repair square function bug --- Sprint-2/1-key-errors/2.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..0ea310abc5 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,24 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +/*An error will occur because a number was used as a function parameter instead of a variable name.*/ function square(3) { return num * num; } // =============> write the error message here +//SyntaxError: Unexpected number // =============> explain this error message here +/*The error happens because JavaScript expects a variable name inside the function brackets, but it found a number instead.*/ // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num +} +console.log(square(3)); From 36a44d55f54c8b90bc06b73d0648cb7a58e44f8b Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:45:23 +0200 Subject: [PATCH 21/28] fix: return value from multiply instead of logging to fix undefined output --- Sprint-2/2-mandatory-debug/0.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..184767c3c1 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here +/*The code will print a correct multiplication inside the function*/ function multiply(a, b) { console.log(a * b); @@ -9,6 +10,13 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +/*The result shows undefined because the function prints the answer with console.log instead of returning it, so nothing is passed back into the template string.*/ // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From 06a880c0a5d6412dccaa6899dcd4c8b5fd184a03 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:51:30 +0200 Subject: [PATCH 22/28] fix: remove early return and return sum correctly --- Sprint-2/2-mandatory-debug/1.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..d28b1df213 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here - +//The sum of 10 and 32 is undefined function sum(a, b) { return; a + b; @@ -9,5 +9,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + +/*The function returns undefined because the return; statement ends the function immediately, so the calculation a + b never runs or gets returned.*/ + // Finally, correct the code to fix the problem // =============> write your new code here + +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 2c1769a0db1a656a5a8ec10bfbeeb7fe27879e57 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 20:21:41 +0200 Subject: [PATCH 23/28] fix: use function parameter instead of global variable in getLastDigit --- Sprint-2/2-mandatory-debug/2.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..0ee01c7f47 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,11 @@ // Predict the output of the following code: // =============> Write your prediction here +/*The output will be: + +The last digit of 42 is 3 +The last digit of 105 is 3 +The last digit of 806 is 3*/ const num = 103; @@ -15,10 +20,28 @@ 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 + +/*The last digit of 42 is 3 +The last digit of 105 is 3 +The last digit of 806 is 3*/ + // Explain why the output is the way it is // =============> write your explanation here + +/*The function always returns the last digit of 103 because it ignores the input parameter and uses a fixed global variable instead of the number passed into it.*/ + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(number) { + return number.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)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +/*The function is not working properly because it ignores the input values and always uses the global variable num (which is 103), so every result returns the last digit of 103 instead of the number passed into the function.*/ From 2c5e84be150022a8de5aa12143ab2348a04c0c03 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 20:49:44 +0200 Subject: [PATCH 24/28] implement BMI function --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..6ff5f6d1b0 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // 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 + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); // return the BMI of someone based off their weight and height +} +console.log(calculateBMI(80, 1.73)); From a76bb457cec13afa85826db6f0dbe2e2aac8148c Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 21:06:32 +0200 Subject: [PATCH 25/28] feat: convert string to UPPER_SNAKE_CASE using split, map, and join --- Sprint-2/3-mandatory-implement/2-cases.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..6764997dc0 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,13 @@ // 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 + +function toUpperSnakeCase(str) { + return str + .split(" ") + .map((word) => word.toUpperCase()) + .join("_"); +} + +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); From 6ed652229925cbfc5a488cf5e5f00ffc5bc275f0 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 21:16:43 +0200 Subject: [PATCH 26/28] feat: convert toPounds script into reusable function and add test cases --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..97e8b43b72 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,18 @@ // 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 + +function toPounds(penceString) { + const withoutP = penceString.slice(0, -1); + + const padded = withoutP.padStart(3, "0"); + + const pounds = padded.slice(0, -2); + const pence = padded.slice(-2); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("399p")); +console.log(toPounds("45p")); +console.log(toPounds("5p")); From 04c466b95eb83202d30377accc44d44433a23e78 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 21:23:58 +0200 Subject: [PATCH 27/28] interpret code --- Sprint-2/4-mandatory-interpret/time-format.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..40dd94e864 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -22,17 +22,23 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// a) 3 times // 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 +// b) 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +// c) "00" // 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 +// d) 1, because the last time pad is called it is for the remaining seconds which is 1 second in this case // 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 + +// e) "01", because the last time pad is called it is for the remaining seconds which is 1 second in this case, and pad adds a leading zero to make it two digits From e00d0c199c5187092c062035b025d1cb9a567f82 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:39:41 +0200 Subject: [PATCH 28/28] Remove Sprint-1 from PR --- Sprint-1/1-key-exercises/1-count.js | 7 --- Sprint-1/1-key-exercises/2-initials.js | 15 ------ Sprint-1/1-key-exercises/3-paths.js | 47 ----------------- Sprint-1/1-key-exercises/4-random.js | 19 ------- Sprint-1/2-mandatory-errors/0.js | 2 - Sprint-1/2-mandatory-errors/1.js | 4 -- Sprint-1/2-mandatory-errors/2.js | 5 -- Sprint-1/2-mandatory-errors/3.js | 16 ------ Sprint-1/2-mandatory-errors/4.js | 4 -- .../1-percentage-change.js | 52 ------------------- .../3-mandatory-interpret/2-time-format.js | 46 ---------------- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 38 -------------- Sprint-1/4-stretch-explore/chrome.md | 18 ------- Sprint-1/4-stretch-explore/objects.md | 16 ------ Sprint-1/readme.md | 35 ------------- 15 files changed, 324 deletions(-) delete mode 100644 Sprint-1/1-key-exercises/1-count.js delete mode 100644 Sprint-1/1-key-exercises/2-initials.js delete mode 100644 Sprint-1/1-key-exercises/3-paths.js delete mode 100644 Sprint-1/1-key-exercises/4-random.js delete mode 100644 Sprint-1/2-mandatory-errors/0.js delete mode 100644 Sprint-1/2-mandatory-errors/1.js delete mode 100644 Sprint-1/2-mandatory-errors/2.js delete mode 100644 Sprint-1/2-mandatory-errors/3.js delete mode 100644 Sprint-1/2-mandatory-errors/4.js delete mode 100644 Sprint-1/3-mandatory-interpret/1-percentage-change.js delete mode 100644 Sprint-1/3-mandatory-interpret/2-time-format.js delete mode 100644 Sprint-1/3-mandatory-interpret/3-to-pounds.js delete mode 100644 Sprint-1/4-stretch-explore/chrome.md delete mode 100644 Sprint-1/4-stretch-explore/objects.md delete mode 100644 Sprint-1/readme.md diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index 226bae22f3..0000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,7 +0,0 @@ -let count = 0; - -count = count + 1; - -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing -// line 3 increments count by 1 and reassigns updated value back to the count variable diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js deleted file mode 100644 index fc0a806a73..0000000000 --- a/Sprint-1/1-key-exercises/2-initials.js +++ /dev/null @@ -1,15 +0,0 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -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 firstName = "Chris"; -let middleName = "Kevin"; -let lastName = "Jones"; - -let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; - -console.log(initials); -// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js deleted file mode 100644 index 2a06cf8010..0000000000 --- a/Sprint-1/1-key-exercises/3-paths.js +++ /dev/null @@ -1,47 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); - -// Create a variable to store the dir part of the filePath variable -// Create a variable to store the ext part of the variable - -const filePath = "Documents/work/report.pdf"; - -const lastSlashIndex = filePath.lastIndexOf("/"); -const lastDotIndex = filePath.lastIndexOf("."); - -const dir = filePath.slice(0, lastSlashIndex); -const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); - -console.log(dir); -console.log(ext); - -const lastSlashIndex = filePath.lastIndexOf("/"); -const lastDotIndex = filePath.lastIndexOf("."); - -// Store the directory -const dir = filePath.slice(0, lastSlashIndex); - -// Store the extension -const ext = lastDotIndex === -1 ? "" : filePath.slice(lastDotIndex); - -console.log(dir); -console.log(ext); -lastDotIndex; - -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 diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js deleted file mode 100644 index dec44ebe20..0000000000 --- a/Sprint-1/1-key-exercises/4-random.js +++ /dev/null @@ -1,19 +0,0 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// In this exercise, you will need to work out what num represents? -// Try breaking down the expression and using documentation to explain what it means -// It will help to think about the order in which expressions are evaluated -// Try logging the value of num and running the program several times to build an idea of what the program is doing - -// Print the random number to the console -console.log(num); - -//num is a random whole number between 1 and 100. - -//Math.random() creates a random decimal. -//Multiply by the range size. -// Math.floor() rounds down. -// Add minimum so it starts at 1. diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js deleted file mode 100644 index e9c7b03f21..0000000000 --- a/Sprint-1/2-mandatory-errors/0.js +++ /dev/null @@ -1,2 +0,0 @@ -/*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?*/ diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js deleted file mode 100644 index 031839b47d..0000000000 --- a/Sprint-1/2-mandatory-errors/1.js +++ /dev/null @@ -1,4 +0,0 @@ -// trying to create an age variable and then reassign the value by 1 - -let age = 33; -age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js deleted file mode 100644 index 2865eb8a42..0000000000 --- a/Sprint-1/2-mandatory-errors/2.js +++ /dev/null @@ -1,5 +0,0 @@ -// Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? - -const cityOfBirth = "Bolton"; -console.log(`I was born in ${cityOfBirth}`); diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js deleted file mode 100644 index 66b49cc0e6..0000000000 --- a/Sprint-1/2-mandatory-errors/3.js +++ /dev/null @@ -1,16 +0,0 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.toString().slice(-4); - -// The last4Digits variable should store the last 4 digits of cardNumber -// However, the code isn't working -// Before running the code, make and explain a prediction about why the code won't work -// 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 predict the code will not work because cardNumber is a number and .slice() is used on strings (or arrays), not numbers. -//When you run it, JavaScript gives an error which is TypeError: cardNumber.slice is not a function -//the reason is because creates a number, and numbers do not have a .slice() method. -//the fix is converting the number to a string - -console.log(last4Digits); diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js deleted file mode 100644 index 1c45f420ca..0000000000 --- a/Sprint-1/2-mandatory-errors/4.js +++ /dev/null @@ -1,4 +0,0 @@ -const twelveHourClockTime = "8:53pm"; -const twentyFourHourClockTime = "20:53"; - -//the code will fail because variable names cannot start with a number diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js deleted file mode 100644 index ab5f87d288..0000000000 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ /dev/null @@ -1,52 +0,0 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - -//answers - -/* a) there are there five - carPrice.replaceAll(",", "") - Number(carPrice.replaceAll(",", "")) - Number(priceAfterOneYear.replaceAll(",", "")) - console.log(...) - - (priceDifference / carPrice) * 100 - line 7 (this is an expression that involves division and multiplication, but it does not involve a function call)*/ - - -/* b) priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); -The issue is a syntax mistake in the brackets/quotes, and JavaScript throws a SyntaxError before running. - -the fix would be priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); - -*/ - -/* c)carPrice = Number(carPrice.replaceAll(",", "")); - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));*/ - -/* d) let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100;*/ - -/* e)carPrice is a string: - replaceAll(",", "") removes commas: - Number(...) converts string to a number: - Convert a formatted string number into a real numeric value so calculations can work.*/ diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js deleted file mode 100644 index 5814f9c992..0000000000 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ /dev/null @@ -1,46 +0,0 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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 -const movieLength = 8784; -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;*/ - -// b) How many function calls are there? - -/* there is one function call - 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 -//The % operator is called the modulus (remainder) operator. -//it means Divide movieLength by 60 and return the remainder - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -//This means:Convert the total seconds into full minutes without the leftover seconds - -// e) What do you think the variable result represents? Can you think of a better name for this variable? - -//A time format (hours:minutes:seconds) for the movie length, a better name would be movieDuration - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer - -//No, it will not work perfectly for all values. -//It does not add leading zeros (so you get 2:5:7 instead of 02:05:07) -//The format can look wrong for some numbers diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index 9c6bc8614e..0000000000 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,38 +0,0 @@ -//Creates a string that represents a price in pence (with a “p” at the end). -const penceString = "399p"; - -/*Removes the last character "p" -So "399p" becomes "399".*/ -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); - -//Makes sure the number has at least 3 digits. -//If it's shorter, it adds leading zeros. -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); - -//Takes everything except the last 2 digits. -//This becomes the pounds part. -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); - -//Takes the last 2 digits as pence. -//If needed, it adds a trailing zero to make sure it always has 2 digits. -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -//Prints the final formatted price in pounds and pence format. -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md deleted file mode 100644 index e7dd5feafe..0000000000 --- a/Sprint-1/4-stretch-explore/chrome.md +++ /dev/null @@ -1,18 +0,0 @@ -Open a new window in Chrome, - -then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -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? - -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? -What is the return value of `prompt`? diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md deleted file mode 100644 index 0216dee56a..0000000000 --- a/Sprint-1/4-stretch-explore/objects.md +++ /dev/null @@ -1,16 +0,0 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -Open the Chrome devtools Console, type in `console.log` and then hit enter - -What output do you get? - -Now enter just `console` in the Console, what output do you get back? - -Try also entering `typeof console` - -Answer the following questions: - -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? diff --git a/Sprint-1/readme.md b/Sprint-1/readme.md deleted file mode 100644 index 62d24c9580..0000000000 --- a/Sprint-1/readme.md +++ /dev/null @@ -1,35 +0,0 @@ -# 🧭 Guide to Week 1 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/1/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. - -This README will guide you through the different sections for this week. - -## 1 Exercises - -In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 2 Errors - -In this section, you'll need to go to each file in `errors` directory and 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. - -## 3 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. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 4 Explore - Stretch 💪 - -This stretch activity will get you to start exploring new concepts and environments by yourself. It will do so by prompting you to reflect on some questions.