From 299b451f310d2c11ef239e750ce3a9a31a58f249 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 11 Oct 2025 13:17:11 +0100 Subject: [PATCH 1/3] Sprint2/2/0.js --- Sprint-2/2-mandatory-debug/0.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..79d72e1f6 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,22 @@ // Predict and explain first... // =============> write your prediction here +// PREDICTION: The function will log the result of the multiplication, but the template literal will not include the result because multiply() does not return a value. -function multiply(a, b) { - console.log(a * b); -} +// 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 +// EXPLANATION: The multiply function logs the product of a and b, but it does not return any value. When we try to use multiply(10, 32) inside the template literal, it evaluates to undefined because there is no return statement in the function. Therefore, the output will be "The result of multiplying 10 and 32 is 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)}`); From 4e6985ad70343ebb3644f63e5bd36d0063135052 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 11 Oct 2025 13:33:23 +0100 Subject: [PATCH 2/3] Sprint2/2/1.js --- Sprint-2/2-mandatory-debug/1.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..77e4b49a9 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,21 @@ // Predict and explain first... // =============> write your prediction here +// PREDICTION: The function will not return the sum because the return statement is placed before the actual addition operation. -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 +// The return statement is placed before the addition operation, so the function will return undefined instead of the sum. + // 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)}`); \ No newline at end of file From 51a54b4a8f094775f756347cdb6ebeb138227b9a Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 11 Oct 2025 13:40:50 +0100 Subject: [PATCH 3/3] Sprint2/2/2.js --- Sprint-2/2-mandatory-debug/2.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..18a5e619a 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,38 @@ // Predict the output of the following code: // =============> Write your prediction here +// PREDICTION: The function will log the last digit of the number passed to it, but it will not work as intended because the num variable is defined outside the function and is not being passed as an argument. -const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// const num = 103; -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)}`); +// function getLastDigit() { +// return num.toString().slice(-1); +// } + +// console.log(`The last digit of 42 is ${getLastDigit(42)}`); +// console.log(`The last digit of 105 is ${getLastDigit(105)}`); +// console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction + // =============> write the output here +// 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 +// The output is not as expected because the getLastDigit function is not using the argument passed to it. Instead, it is using the num variable defined outside the function, which is not being updated with the new values. // =============> write your explanation here +// The getLastDigit function should take a number as an argument and return the last digit of that number. However, it is currently using the num variable defined outside the function, which is not being updated with the new values passed to the function. // 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 ${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 getLastDigit function should take a number as an argument and return the last digit of that number. However, it is currently using the num variable defined outside the function, which is not being updated with the new values passed to the function. \ No newline at end of file