From 80356352ff57888f30d37eb81c6214360441c306 Mon Sep 17 00:00:00 2001 From: Segun Date: Wed, 19 Feb 2025 12:57:16 +0000 Subject: [PATCH 1/8] Sprint-2-update --- Sprint-2/1-key-errors/0.js | 14 ++++++++++---- Sprint-2/1-key-errors/1.js | 15 ++++++++++++--- Sprint-2/1-key-errors/2.js | 18 +++++++++++------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..24a7387e8 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,19 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: The code will not run because "let" should not be use in a function. -// call the function capitalise with a string input -// interpret the error message and figure out why an error is occurring +// call the function capitalise with a string input: done +// interpret the error message and figure out why an error is occurring: says string has already been declared. As said earlier "let" should be eliminated function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here + +// =============> write your explanation here: +// Let is not needed to declare a variable inside a function. // =============> write your new code here +function capitalise(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 f2d56151f..44e00f4fb 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... -// Why will an error occur when this program runs? -// =============> write your prediction here +// Why will an error occur when this program runs? decimalNumber should be assigned a value outside the function only. +// =============> write your prediction here: const decimalNumber = 0.5 will give an error message. // Try playing computer with the example to work out what is going on @@ -14,7 +14,16 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> write your explanation here: The re-assignment of decimal number inside the function is unecessary // 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)); \ 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..f20db3f8e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,22 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here: There is going to be an error message. As there should be a variable in place of "3" -function square(3) { - return num * num; -} +//function square(3) { + //return num * num; +//} + +// =============> write the error message here: SyntaxError: Unexpected Number -// =============> write the error message here +// =============> explain this error message here: As there should be a variable in place of "3" -// =============> explain this error message here // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num*num; +} - +console.log(square(3)); From 94903a3d349d447c09e6dc97f5b086b9169c3ce1 Mon Sep 17 00:00:00 2001 From: Segun Date: Wed, 19 Feb 2025 13:52:59 +0000 Subject: [PATCH 2/8] sprint 2...updates --- Sprint-2/1-key-errors/2.js | 6 +++--- Sprint-2/2-mandatory-debug/0.js | 13 ++++++++++--- Sprint-2/2-mandatory-debug/1.js | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index f20db3f8e..72068724d 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,9 +5,9 @@ // =============> write your prediction of the error here: There is going to be an error message. As there should be a variable in place of "3" -//function square(3) { - //return num * num; -//} +function square(3) { + return num * num; +} // =============> write the error message here: SyntaxError: Unexpected Number diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..511536e6c 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,21 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: the function has no return. Hence multiply ${multiply(10, 32)} will return undefined. 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: +// console.log(a*b) logs the result of the multiplication to the console but does not return any value. // 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 37cedfbcf..6d8fc2f0f 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// ${sum(10, 32)} will return 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 +//Inside the function, return should not be followed by a semi-colon // 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 9295c66effd6f98489dfb3c992ead81598d93273 Mon Sep 17 00:00:00 2001 From: Segun Date: Fri, 21 Feb 2025 20:24:42 +0000 Subject: [PATCH 3/8] update 1/21/02 --- Sprint-2/2-mandatory-debug/1.js | 8 ++++---- Sprint-2/2-mandatory-debug/2.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 6d8fc2f0f..0fc83e08f 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -2,10 +2,10 @@ // =============> write your prediction here // ${sum(10, 32)} will return 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)}`); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..9b5b46555 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here +// The code will only output for the number declared first const num = 103; @@ -15,10 +16,26 @@ 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 +//Output +//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 code will also return the last digit of num because the code does not accept parameters // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +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 From ed867daa3c89766d753d81172cb70637055ccba3 Mon Sep 17 00:00:00 2001 From: Segun Date: Fri, 21 Feb 2025 21:11:57 +0000 Subject: [PATCH 4/8] Aupdate21/02 --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 +++- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ 2 files changed, 7 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..f44adf807 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,6 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + return weight/(height**2) +} +console.log(calculateBMI(60,1.65)); \ 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..071ea8411 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 ChangeCasePluseSnake(str){ + return str.toUpperCase().replace(" ","_"); +}; +console.log(ChangeCasePluseSnake("Hello World")); \ No newline at end of file From 30bf077bcc4c0aa4734169f646e91ba8722a9ad6 Mon Sep 17 00:00:00 2001 From: Segun Date: Sat, 22 Feb 2025 00:49:53 +0000 Subject: [PATCH 5/8] update 1/22/02 --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..b6c72e977 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,24 @@ // 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 penceChange(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"); + +return `£${pounds}.${pence}`}; + +console.log(penceChange("300p")); From 168045e503cc615dcdaee75bb51f88e7047c292a Mon Sep 17 00:00:00 2001 From: Segun Date: Sun, 23 Feb 2025 19:48:23 +0000 Subject: [PATCH 6/8] time-format.js --- 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 7c98eb0e8..62abc16c6 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,7 +10,7 @@ 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 @@ -18,6 +18,7 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +//pad will be called three times // Call formatTimeDisplay with an input of 61, now answer the following: From 1c5356a21f34014f12b14dcfc78f54724174c01b Mon Sep 17 00:00:00 2001 From: Segun Date: Sun, 23 Feb 2025 21:35:39 +0000 Subject: [PATCH 7/8] additions23/02 --- Sprint-2/4-mandatory-interpret/time-format.js | 5 ++++- Sprint-3/1-key-implement/1-get-angle-type.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 62abc16c6..9efd44c88 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -24,12 +24,15 @@ console.log(formatTimeDisplay(61)); // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here +//Value assigned will be 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here - +// The return 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 assigned value is 1 // 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 diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..4fc80cb40 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -9,6 +9,8 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; + else if (angle < 90) return "Acute angle"; + else if (angle >90 && angle <180) return "Obtuse angle"; // read to the end, complete line 36, then pass your test here } @@ -43,6 +45,7 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); +assertEquals(obtuse,"Obtuse angle"); // ====> write your test here, and then add a line to pass the test in the function above // Case 4: Identify Straight Angles: From 13fc7318ec2b6f946d18398b576966f280edf996 Mon Sep 17 00:00:00 2001 From: Segun Date: Fri, 4 Apr 2025 21:02:10 +0100 Subject: [PATCH 8/8] moreerrorcorrections --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 +++- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 2 files 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 f44adf807..1de80907d 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,6 +16,8 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height - return weight/(height**2) + const BM = weight/(height**2) // These are modifications based on review. + const BMI = BM.toFixed(1); //Theses are modifications based on review. + return BMI } console.log(calculateBMI(60,1.65)); \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 9efd44c88..102f94fa6 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,7 +18,7 @@ console.log(formatTimeDisplay(61)); // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here -//pad will be called three times +//pad will be called three timesgit // Call formatTimeDisplay with an input of 61, now answer the following: