From 5abf1f56e30e9f68145924aa3b4abdfb78a80565 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 7 Mar 2026 19:02:44 +0000 Subject: [PATCH 1/7] Done coursework/sprint-2 --- Sprint-2/1-key-errors/0.js | 12 ++++++++++++ Sprint-2/1-key-errors/1.js | 13 +++++++++++++ Sprint-2/1-key-errors/2.js | 11 ++++++++++- Sprint-2/2-mandatory-debug/0.js | 12 ++++++++++++ Sprint-2/2-mandatory-debug/1.js | 8 ++++++++ Sprint-2/2-mandatory-debug/2.js | 16 +++++++++++++++- Sprint-2/3-mandatory-implement/1-bmi.js | 9 +++++++-- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 5 +++++ Sprint-2/4-mandatory-interpret/time-format.js | 6 +++++- 10 files changed, 91 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..fb4c078733 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// The program will give an error.The error happens because `str`is written twice inside the function. + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -10,4 +12,14 @@ function capitalise(str) { } // =============> write your explanation here +// The function already has an input called `str` +// Inside the function, the code tries to create another variable called `str`using `let` +//JavaScript does not allow the same varible name to be created again in same place. +//Because of this, the program throwns an error. + // =============> write your new code here + +function captialise(str){ + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..ddaae9d092 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -3,6 +3,9 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// The program will give an error because of the `decimalNumber` is used outside the function. +// Even though it is only created inside the function. + // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { @@ -16,5 +19,15 @@ console.log(decimalNumber); // =============> write your explanation here +//The variable `decimalNumber`is only insdie the function. +// At the end of the program, console.log( decimalNumber) tries to print it , +// however, JavaScript cannot find that varible outside the function. +// Because of this, the program throws an error. + // 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)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..696bd74b0e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,29 @@ // Predict and explain first BEFORE you run any code... +// The program will give a SyntazError because a number (3) is used as peramter name in the function. // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// My perdiction is that program will not run and show a SyntaxError because 3 is not a valid variable name. function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// Funtion parameters must be variable names. +// You cannot use a number like 3 as name of parameter. +//Javascript required a valid varible name inside the parentheses. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..d3c7109245 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,9 @@ // Predict and explain first... // =============> write your prediction here +// The program will print 320 first. +// Then it will " The result of mutiplying 10 and 32 is undefined". + function multiply(a, b) { console.log(a * b); @@ -9,6 +12,15 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The function multiply is used console.log(a * b) to show the result +// however, it does not resturn the value . +// when the function is used inside the sentence with ${multiply(10, 32)} +// JavaScript expects the function to give back a value. +//Becuse the function does not return anything, the result becomes undefined. // 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)} `); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..a4d5d22aa3 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +//My perdiction the code will show "undefined" becuse the function does not return the sum numbers. function sum(a, b) { return; @@ -9,5 +10,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The return statemment is ematy and the "c=b" is written after return. +//When JavaScript see return it stops the function, so a+b is never used. + // 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)}`); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..c7eecb5703 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,7 @@ // Predict and explain first... - // Predict the output of the following code: // =============> Write your prediction here +//The code will always show 3 as the last digit because the function does not use the number inside getLastDigit(). const num = 103; @@ -15,10 +15,24 @@ 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 does not take any input parameter, it always uses the global variavle num = 103. +// Because of this the last digit returend is always 3, regardless of the number passed in the function call. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} +console.log(`The last digit of 42 is $(getlastDigita(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 was fixed by adding a parameter so it can return the last digit of the given number. diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..0f0d404889 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // 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 + // return the BMI of someone based off their weight and height +} + +function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); +} diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..425f388689 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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 convertToUpperSnakeCase(str) { + return str.toUpperCase().trim().split("").join("_"); +} diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..cd1f813321 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,8 @@ // 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(kilograms) { + const pounds = kilograms * 2.20462; + return Number(pounds.toFixed(2)); +} diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..4063821dde 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,21 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// Pad wil be called 3 times because the return statement uses pad for hours, mintues and seconds. // 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 +// The value is 0 because totalHours is 0 when the input is 61 seconds. // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value is "00" because padStart makes the number two digits by adding a 0 at the start. // 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 - +// The value is 1 because the last call to pad uses remainingSeconds, which is 1 when the input is 61. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer // =============> write your answer here +// The return value is "01" because padStart adds a 0 infornt of the single digit number. From 045a934c41fd056dcd156f1e513df616ee6d259e Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 14 Mar 2026 08:47:16 +0000 Subject: [PATCH 2/7] I have fixed the mistakes according to the feedabck. --- Sprint-2/2-mandatory-debug/0.js | 3 ++- Sprint-2/3-mandatory-implement/2-cases.js | 4 +++- Sprint-2/3-mandatory-implement/3-to-pounds.js | 23 +++++++++++++++---- .../implement/2-is-proper-fraction.js | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index d3c7109245..d7974e42ab 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,7 +2,7 @@ // =============> write your prediction here // The program will print 320 first. -// Then it will " The result of mutiplying 10 and 32 is undefined". +// Then it will " The result of mutiplying 10 and 32 is 320". function multiply(a, b) { @@ -23,4 +23,5 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); function multiply(a,b){ return a*b; } + console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)} `); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 425f388689..a6c4853597 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -16,5 +16,7 @@ // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase function convertToUpperSnakeCase(str) { - return str.toUpperCase().trim().split("").join("_"); + return str.toUpperCase().trim().split(" ").join("_"); } + +console.log(convertToUpperSnakeCase("hello there")); // "HELLO_THERE" diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index cd1f813321..2f2b181dda 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,7 +5,22 @@ // You should call this function a number of times to check it works for different inputs -function toPounds(kilograms) { - const pounds = kilograms * 2.20462; - return Number(pounds.toFixed(2)); -} +const toPounds = (kg) => +(kg * 2.20462).toFixed(2); + +const penceToPounds = (p) => `£${(p / 100).toFixed(2)}`; +const toUpperSnakeCase = (s) => s.toUpperCase().trim().split(" ").join("_"); +const multiply = (a, b) => a * b; + +// Tests +console.log(toPounds(10)); // 22.05 + +console.log(penceToPounds(150)); // "£1.50" + +console.log(toUpperSnakeCase("hello there")); +// "HELLO_THERE" +console.log(multiply(10, 32)); // 320 + +const convertToUpperSnakeCase = (str) => + str.toUpperCase().trim().split(" ").join("_"); + +console.log(convertToUpperSnakeCase("hello there")); // "HELLO_THERE" diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..1e619b39eb 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -30,4 +30,4 @@ function assertEquals(actualOutput, targetOutput) { // What combinations of numerators and denominators should you test? // Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 2), true); From 6b5e82d56ac77f7b9957f5d7a7ff657ef097fca5 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 14 Mar 2026 11:53:05 +0000 Subject: [PATCH 3/7] Just made changes on question --- Sprint-2/1-key-errors/2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 696bd74b0e..cdc3652725 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -7,9 +7,9 @@ // =============> write your prediction of the error here // My perdiction is that program will not run and show a SyntaxError because 3 is not a valid variable name. -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here // SyntaxError: Unexpected number From a625e694972aaedb42afbe2153aa6f80befa2132 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 14 Mar 2026 12:06:22 +0000 Subject: [PATCH 4/7] Restore files --- .../implement/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 1e619b39eb..970cb9b641 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -30,4 +30,4 @@ function assertEquals(actualOutput, targetOutput) { // What combinations of numerators and denominators should you test? // Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(1, 2), true); From 9b3eb4b687e97668b07b25732f9a67a512c7724f Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 14 Mar 2026 13:31:13 +0000 Subject: [PATCH 5/7] Applied the feedback --- Sprint-2/2-mandatory-debug/0.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index d7974e42ab..cb9e33c3f3 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -4,7 +4,6 @@ // The program will print 320 first. // Then it will " The result of mutiplying 10 and 32 is 320". - function multiply(a, b) { console.log(a * b); } @@ -14,14 +13,14 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here // The function multiply is used console.log(a * b) to show the result // however, it does not resturn the value . -// when the function is used inside the sentence with ${multiply(10, 32)} +// when the function is used inside the sentence with ${multiply(10, 32)} // JavaScript expects the function to give back a value. //Becuse the function does not return anything, the result becomes undefined. // 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)} `); +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)} `); From 41d76e20a24318e43dd965dd79787ded6dd5eb8f Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 14 Mar 2026 23:30:38 +0000 Subject: [PATCH 6/7] Exaplined why implement 4 different functions in this file. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 2f2b181dda..fe5445b196 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -24,3 +24,10 @@ const convertToUpperSnakeCase = (str) => str.toUpperCase().trim().split(" ").join("_"); console.log(convertToUpperSnakeCase("hello there")); // "HELLO_THERE" + +// Four functions are implemented because each one performs a specific task. +// This makes the code easier to read, reuse, and maintain. +// +// The penceToPounds function was updated to handle a pence string like "399p". +// It removes the "p", converts the value to a number, and divides by 100 +// so the function correctly returns "£3.99".s From dee92a3bc99e7efb89fe508f98f4185f39593de8 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Wed, 18 Mar 2026 23:26:48 +0000 Subject: [PATCH 7/7] Fixed the issues --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index fe5445b196..4a1ba44eec 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,29 +5,12 @@ // You should call this function a number of times to check it works for different inputs -const toPounds = (kg) => +(kg * 2.20462).toFixed(2); - -const penceToPounds = (p) => `£${(p / 100).toFixed(2)}`; -const toUpperSnakeCase = (s) => s.toUpperCase().trim().split(" ").join("_"); -const multiply = (a, b) => a * b; +const penceToPounds= (p) => { + const value = parseInt(p.replace("p", "")); + return `£${(value / 100).toFixed(2)}`; +}; // Tests -console.log(toPounds(10)); // 22.05 - -console.log(penceToPounds(150)); // "£1.50" - -console.log(toUpperSnakeCase("hello there")); -// "HELLO_THERE" -console.log(multiply(10, 32)); // 320 - -const convertToUpperSnakeCase = (str) => - str.toUpperCase().trim().split(" ").join("_"); +console.log(penceToPounds("399p")); // "£3.99" -console.log(convertToUpperSnakeCase("hello there")); // "HELLO_THERE" -// Four functions are implemented because each one performs a specific task. -// This makes the code easier to read, reuse, and maintain. -// -// The penceToPounds function was updated to handle a pence string like "399p". -// It removes the "p", converts the value to a number, and divides by 100 -// so the function correctly returns "£3.99".s