From 68316a4dc2b2be482a9901f7eb48228d7aecc46a Mon Sep 17 00:00:00 2001 From: delmorallopez <124817272+delmorallopez@users.noreply.github.com> Date: Tue, 10 Jun 2025 20:03:18 +0100 Subject: [PATCH 1/5] Spring2-Key-errors --- Sprint-2/1-key-errors/0.js | 23 +++++++++++++++++++---- Sprint-2/1-key-errors/1.js | 18 +++++++++++------- Sprint-2/1-key-errors/2.js | 9 ++++++++- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..7d6b40c20 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,28 @@ // Predict and explain first... // =============> write your prediction here +// declare str again inside the function, which causes a syntax error + + // 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; -} // =============> write your explanation here + +// str[0].toUpperCase() → capitalizes the first letter. + +// str.slice(1) → returns the rest of the string starting from index 1. + +// Combines both parts into a new string. + + // =============> write your new code here + +function capitalise(str) { + let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalised; +} + +console.log(capitalise("hello")); // "Hello" +console.log(capitalise("jesus")); // "Jesus" diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..bc3cfcc23 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,24 @@ // Predict and explain first... +// We are not calling to the function from console.log, the function is convertToPercentage +// Also, its using decimalNumber outside the function, decimalnumber is a parameter it’s not defined in the global scope. + // Why will an error occur when this program runs? // =============> write your prediction here // Try playing computer with the example to work out what is going on + +// =============> write your explanation here + +// Finally, correct the code to fix the problem +// =============> write your new code here + function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(decimalNumber); - -// =============> write your explanation here +console.log(convertToPercentage(0.5)); // "50%" +console.log(convertToPercentage(0.25)); // "25%" -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..36f2cc294 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,10 +5,17 @@ // =============> write your prediction of the error here -function square(3) { +// It will get an error because as parameter to the function is a integer (3) +// Also num is not declare in anywhere + +function square(num) { return num * num; } +console.log(square(3)); + + + // =============> write the error message here // =============> explain this error message here From 3dfcb63a89a8da0c50c0637c56deb38bb28e21bf Mon Sep 17 00:00:00 2001 From: delmorallopez <124817272+delmorallopez@users.noreply.github.com> Date: Tue, 10 Jun 2025 20:43:48 +0100 Subject: [PATCH 2/5] Spring2/mandatory-debug --- Sprint-2/2-mandatory-debug/0.js | 4 +++- Sprint-2/2-mandatory-debug/1.js | 6 ++++-- Sprint-2/2-mandatory-debug/2.js | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..b1819d908 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,9 +1,11 @@ // Predict and explain first... +// The function should return a variable, the current function doesn't return anything, just console.log() + // =============> write your prediction here function multiply(a, b) { - console.log(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 37cedfbcf..a0c1474d6 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,9 +1,11 @@ // Predict and explain first... + +//The function is not returning anything + // =============> write your prediction here function sum(a, b) { - return; - 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..db4719b80 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,15 @@ // Predict and explain first... // Predict the output of the following code: + +// Will be an error because we are not passing a parameter in the function getLastDigit +// the value of num is taking always the value 103, it declarate at the beginning of the program + // =============> Write your prediction here -const num = 103; +// const num = 103; -function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } From 74c17d0dad8c2b1e1baca4a04aaf405f537cc350 Mon Sep 17 00:00:00 2001 From: delmorallopez <124817272+delmorallopez@users.noreply.github.com> Date: Tue, 10 Jun 2025 21:30:11 +0100 Subject: [PATCH 3/5] Spring2/mandatory-implement --- Sprint-2/3-mandatory-implement/1-bmi.js | 9 +++++- Sprint-2/3-mandatory-implement/2-cases.js | 10 +++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..7cd8715e0 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,11 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + const bmi = 0 + + height = height * height; + return(weight / height).toFixed(1); +} + + +console.log(calculateBMI(72, 1.80)); \ 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..d3520245c 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 + .trim() // Remove leading/trailing whitespace + .toUpperCase() // Convert to uppercase + .replace(/\s+/g, '_'); // Replace spaces with underscores + } + + console.log(toUpperSnakeCase('hello world')); + console.log(toUpperSnakeCase('lord of the rings')); \ 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..764668be5 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,32 @@ // 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 penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 +); + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); + +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); + +} + +console.log(toPounds('400p')); + + From 88e1e1dabf5d7334c99f1d688164abc95b2e2c36 Mon Sep 17 00:00:00 2001 From: delmorallopez <124817272+delmorallopez@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:14:17 +0100 Subject: [PATCH 4/5] Sprint2/mandatory-interpret --- Sprint-2/4-mandatory-interpret/time-format.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..2ff5ffb2c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,13 +11,15 @@ 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 function is called 3 times // Call formatTimeDisplay with an input of 61, now answer the following: From ded20ceb6a5b361045e6418fdc1f1002b135da33 Mon Sep 17 00:00:00 2001 From: delmorallopez <124817272+delmorallopez@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:24:26 +0100 Subject: [PATCH 5/5] time-format --- Sprint-2/4-mandatory-interpret/time-format.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 2ff5ffb2c..94edffd77 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -24,13 +24,13 @@ console.log(formatTimeDisplay(61)); // 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 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// The value is 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 +// The value assigned last time we called Pad is 1, but the return is 01 // 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 value is returned is 01