From b4198c8bc4396d3d28cd9198ca7bdfce7362663a Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Feb 2026 17:08:19 +0000 Subject: [PATCH 1/7] first folder redone --- Sprint-2/1-key-errors/0.js | 15 +++++++++++---- Sprint-2/1-key-errors/1.js | 27 +++++++++++++++++++++------ Sprint-2/1-key-errors/2.js | 20 +++++++++++++++----- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..cef89a0e7 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +//there will be an error because str is alrady declared. + // call the function capitalise with a string input // 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; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } // =============> write your explanation here // =============> write your new code here +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise('hello world')); // should return 'Hello world' \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..05a3bb704 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -3,18 +3,33 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// decimalNumber has been declared in the function and the console is logging it outside instead of calling th e function + + // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here +// /home/martinmclean158/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:12 +// const decimalNumber = 0.5; + // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..70f8e8858 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -2,14 +2,21 @@ // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error +// There is no "num" veriabal defined. num should be in the beackets + // =============> write your prediction of the error here -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } + +// // =============> write the error message here +// /home/martinmclean158/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// ^ -// =============> write the error message here +// SyntaxError: Identifier 'str' has already been declared // =============> explain this error message here @@ -17,4 +24,7 @@ function square(3) { // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(3)); // should print 9 From bd9746aa56625a01efd1deadd60e4d8fc760aa64 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Feb 2026 17:18:58 +0000 Subject: [PATCH 2/7] second one done --- Sprint-2/2-mandatory-debug/0.js | 24 +++++++++++++++++------- Sprint-2/2-mandatory-debug/1.js | 17 +++++++++++------ Sprint-2/2-mandatory-debug/2.js | 29 +++++++++++++++++++---------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..338fe5789 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,13 +2,23 @@ // =============> write your prediction here -function multiply(a, b) { - console.log(a * b); -} +// the fuction is not returning anything, so the result of multiplying 10 and 32 will be undefined how ever the function +// is still multiplying the two numbers and printing the result to the console + +// function multiply(a, b) { +// console.log(a * b); +// } -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// // =============> write your explanation here + +// // Finally, correct the code to fix the problem +// // =============> write your new code here +function multiply(a, b) { + const result = a * b; + console.log(result); + return result; +} -// Finally, correct the code to fix the problem -// =============> write your new code here +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..25b9de2e0 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,18 @@ // Predict and explain first... // =============> write your prediction here +//there is nothing being returned so the function will be undefined +// function sum(a, b) { +// return; +// a + b; +// } -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// 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 +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 57d3f5dc3..da11bc447 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,33 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// num is a const so it will al;ways return 3 -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// 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)}`); +// 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 +// =============> yes thay all give 3 // Explain why the output is the way it is -// =============> write your explanation here +// because the variable is a consrent // 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 + + +function getLastDigit(num) { + 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)}`); \ No newline at end of file From f3643c12dfd15014d69ffde47051c5ddf88178f6 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Feb 2026 17:30:53 +0000 Subject: [PATCH 3/7] third times the charm --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..f8f2e0b14 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 + let bmi = weight/(height*height) + return bmi.toFixed(1) +} +console.log(calculateBMI(70,1.73)) \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..81cb62607 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 SNAKE_CASE (mesasge){ + let snake = mesasge.replace(/ /g,"_"); + let upper = snake.toUpperCase(); + return upper; +} +console.log(SNAKE_CASE("hello there")); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..14efd7466 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,13 @@ // 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) { + let penceStringWithoutTrailingP = penceString.replace( /[^1-9]/g, ""); //39772 + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //39772 + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 ); // 397 + const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) +.padEnd(2, "0"); // 72 + return `£${pounds}.${pence}`; // 397.72 + +} +console.log(toPounds("397d72p")); \ No newline at end of file From cae38279e3bd1ad40e40073231bf216f4b67927f Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Feb 2026 17:42:20 +0000 Subject: [PATCH 4/7] last one --- Sprint-2/4-mandatory-interpret/time-format.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..1687907bc 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,25 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)) // 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 +// Pad willo be called 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 +// "null" // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// "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 +// it is assined 1 because 61 - 60 leaves 1 as a remainder // 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 it is padded to at the start to be a minimum string length of 2 From 0e24e1bcdaa249b1cfe2de29c84ff7130f762ccb Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 13 Feb 2026 17:53:50 +0000 Subject: [PATCH 5/7] should all be good this time --- Sprint-2/4-mandatory-interpret/time-format.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 1687907bc..9708348e2 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,18 +18,23 @@ console.log(formatTimeDisplay(61)) // Questions // a) When formatTimeDisplay is called how many times will pad be called? +// =============> write your answer here // Pad willo be called 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 // "null" // c) What is the return value of pad is called for the first time? +// =============> write your answer here // "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 // it is assined 1 because 61 - 60 leaves 1 as a remainder // 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 it is padded to at the start to be a minimum string length of 2 From 588adc5b535bb88cb120b2a1ecc9533cfec00285 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 14 Feb 2026 10:21:29 +0000 Subject: [PATCH 6/7] changed answer to q, B --- Sprint-2/4-mandatory-interpret/time-format.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 9708348e2..776c35675 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -7,6 +7,7 @@ function formatTimeDisplay(seconds) { const totalMinutes = (seconds - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; + console.log(totalHours); return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } @@ -25,7 +26,7 @@ console.log(formatTimeDisplay(61)) // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here -// "null" +// "0" // c) What is the return value of pad is called for the first time? // =============> write your answer here From 7bc12350b1e8d366b5a24290967f0dcf6a8c49fe Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 14 Feb 2026 12:15:52 +0000 Subject: [PATCH 7/7] errors fixed --- Sprint-2/1-key-errors/2.js | 15 +++++++++------ Sprint-2/2-mandatory-debug/0.js | 1 - Sprint-2/2-mandatory-debug/2.js | 2 +- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 70f8e8858..e4ee8000b 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -2,19 +2,22 @@ // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error -// There is no "num" veriabal defined. num should be in the beackets +// // There is no "num" veriabal defined. num should be in the beackets -// =============> write your prediction of the error here +// // =============> write your prediction of the error here // function square(3) { // return num * num; // } -// // =============> write the error message here -// /home/martinmclean158/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 -// let str = `${str[0].toUpperCase()}${str.slice(1)}`; -// ^ +// // // // =============> write the error message here +// // // /home/martinmclean158/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 +// // /home/martinmclean158/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:10 +// // function square(3) { +// ^ + +// SyntaxError: Unexpected number // SyntaxError: Identifier 'str' has already been declared diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 338fe5789..73f566b0d 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -17,7 +17,6 @@ // // =============> write your new code here function multiply(a, b) { const result = a * b; - console.log(result); return result; } diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index da11bc447..9e79506b1 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -16,7 +16,7 @@ // Now run the code and compare the output to your prediction // =============> yes thay all give 3 // Explain why the output is the way it is -// because the variable is a consrent +// because the variable is a const before the code block when num is called it can't be changed // Finally, correct the code to fix the problem // =============> write your new code here diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index f8f2e0b14..cb77fe0e6 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,7 +15,7 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - let bmi = weight/(height*height) + const bmi = weight/(height*height) return bmi.toFixed(1) } console.log(calculateBMI(70,1.73)) \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 81cb62607..a9c0f5522 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,9 +14,9 @@ // 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 SNAKE_CASE (mesasge){ +function toSnakeCase (mesasge){ let snake = mesasge.replace(/ /g,"_"); let upper = snake.toUpperCase(); return upper; } -console.log(SNAKE_CASE("hello there")); \ No newline at end of file +console.log(toSnakeCase("hello there")); \ No newline at end of file