From b610fbeab32d78d1024c8212984bd24d4d59dc1d Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Fri, 26 Jun 2026 00:47:40 +0200 Subject: [PATCH 1/8] completed interpret ,key errors and all mandatory execercise --- Module-Structuring-and-Testing-Data | 1 + 1 file changed, 1 insertion(+) create mode 160000 Module-Structuring-and-Testing-Data diff --git a/Module-Structuring-and-Testing-Data b/Module-Structuring-and-Testing-Data new file mode 160000 index 0000000000..b31a586bf2 --- /dev/null +++ b/Module-Structuring-and-Testing-Data @@ -0,0 +1 @@ +Subproject commit b31a586bf20de09330f37bcf5d708e5ecd67f45b From fc76e95ca7baaf8ceba3c07284e0a64abda60821 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Thu, 2 Jul 2026 01:30:49 +0200 Subject: [PATCH 2/8] Remove Module-Structuring-and-Testing-Data from Sprint 2 --- Module-Structuring-and-Testing-Data | 1 - 1 file changed, 1 deletion(-) delete mode 160000 Module-Structuring-and-Testing-Data diff --git a/Module-Structuring-and-Testing-Data b/Module-Structuring-and-Testing-Data deleted file mode 160000 index b31a586bf2..0000000000 --- a/Module-Structuring-and-Testing-Data +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b31a586bf20de09330f37bcf5d708e5ecd67f45b From f4d4ae527b636437495694df32ec7ba2fa6cc19d Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Thu, 2 Jul 2026 01:32:38 +0200 Subject: [PATCH 3/8] completed all excercises in sprint 2 --- Sprint-2/1-key-errors/0.js | 10 ++++++++++ Sprint-2/1-key-errors/1.js | 11 ++++++++++- Sprint-2/1-key-errors/2.js | 18 ++++++++++++------ Sprint-2/2-mandatory-debug/0.js | 14 +++++++++++--- Sprint-2/2-mandatory-debug/1.js | 6 ++++++ Sprint-2/2-mandatory-debug/2.js | 14 ++++++++++++-- Sprint-2/3-mandatory-implement/1-bmi.js | 6 +++++- Sprint-2/3-mandatory-implement/2-cases.js | 7 +++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 18 ++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 7 +++++++ 10 files changed, 98 insertions(+), 13 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..265bbafa92 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,8 +1,12 @@ // Predict and explain first... // =============> write your prediction here +// when running the code there will be a syntax error because the `str` being a function name has already been declared +// so it cant be returned .so the return variable should have another name // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//Uncaught SyntaxError: Identifier 'str' has already been declared + function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; @@ -10,4 +14,10 @@ function capitalise(str) { } // =============> write your explanation here +// there is an error in the code because the `str` is declared twice and there are unexpected token '}'. + // =============> write your new code here +function capitalise (str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} + diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..350fe5942b 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,9 @@ // Predict and explain first... +// the will be answer of the percentage printed on the console.log.because the function has been declared. // Why will an error occur when this program runs? // =============> write your prediction here +//there will be a code error because of the function has been declared twice. // Try playing computer with the example to work out what is going on @@ -15,6 +17,13 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here - +//when a function is called a value it given to the parameter. // 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)) //50 +console.log (convertToPercentage(0.25)) //25% \ 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 aad57f7cfe..4b4e17ba52 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,26 @@ // Predict and explain first BEFORE you run any code... - +// the will be an error when this code runs because the retrun varaible has not been assigined by a value and there function has not declared a variable. // this function should square any number but instead we're going to get an error - // =============> write your prediction of the error here +// synch equation function square(3) { return num * num; } // =============> write the error message here +// Uncaught SyntaxError: Unexpected number +// > return num * num; + // return num * num; -// =============> explain this error message here +//Uncaught SyntaxError: Illegal return statement +// =============> explain this error message here +// the error is simply saying that the return variable has not been assigned by a value.`illegal statement`. // Finally, correct the code to fix the problem - // =============> write your new code here - - +function square (num){ + return num * num; +} +console.log (square(3)) // 9 \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..a5bcb0e58b 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 +// I predict that the function expression will run a nerro because the are errors in the code .such as the concole.log in line 6. + function multiply(a, b) { - console.log(a * b); +concole.lpg( a* b); + } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here - +// console.log prints out information it does not return any varable to its function.hence the syntax error. +// console.log cant read unprovided information. // Finally, correct the code to fix the problem // =============> write your new code here +function multiply (a,b){ + if (a===10 && b===32){ + let result =a * b ; + } +} \ 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 37cedfbcfd..eec6488db7 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 +//Js doesnt understand this code so it will read as an error because the return varable has not been aissinged any variable. function sum(a, b) { return; @@ -9,5 +10,10 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// js does not read values not assigned to any variable so the will be a syntax error not allowing the code to read . // 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 diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..071628fdad 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,8 @@ -// Predict and explain first... - +// Predict and explain first.. // Predict the output of the following code: // =============> Write your prediction here +// i predict that the output will be 3 for all the numbers passed to the function because the function is not using the parameter +// passed to it instead it is using the variable num which is 103 so it will always return 3 as the last digit of any number passed to it. const num = 103; @@ -15,10 +16,19 @@ 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 output is the way it is because the function getlastDigit is not using the parameter passed to it.instead it is using the variable num which is 103. // Finally, correct the code to fix the problem // =============> write your new code here +// the function getLastDigit(num){ +// return num.string().slice(-1);} // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// this is because the function getLastDigit is not using the parameter passed to it. +// instead it is using the variable num which is 103. so it will always return 3 as the last digit of any number passed to it.s \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..c497b93d19 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,8 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + return Number((weight/(height *height)).toFixed(1)); +} + + + diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..b29ada0ce3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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 touppersneakers (input){ + return input.trim().replace(/\s+/g, "_").touppercase(); +} +console.log(touppersneakers("hello there"));//Hello There +console.log(touppersneakers("lord of the rings")); // lord of the rings +console.log(touppersneakers("good morning")); // GOOD MORNING diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..f6e12ba937 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,21 @@ // 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 toSnakeCase(str) { + const pecestringwithouttrailingp = pencestring.substring(0,pencestring.length -1); + const padded penceNumberstring = pencestringWithoutTrailingP.padstart(3,"0"); + const pounds = paddedpenceNumberString.substring(0, paddedpencenumberstring.length-2); + const pencr= paddedpencenumberstring.substring(paddedpencenumberstring.length -2) + .padEnd(2,"0"); + return £${pounds}.${pence}`; +} +// test the function with different inputs +consloe.log(topounds("399p"), // £3.99 +4console.log(toPounds("9p")); // £0.09 +console.log(toPounds("99p")); // £0.99 +console.log(toPounds("1234p")); // £12.34 + + diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..797932fdaa 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -22,17 +22,24 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// pad will be called 3 times, once for totalHours, once for remainingMinutes, and once for remainingSeconds. // 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 assigned to num when pad is called for the first time is 0, which is the value of totalHours 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 of pad when it is called for the first time is "00", which is the padded string representation of totalHours (0) when the input is 61 seconds. // 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 to num when pad is called for the last time in this program is 1, which is the value of remainingSeconds when the input is 61 seconds. +// This is because 61 seconds is equal to 1 minute and 1 second, so the remaining seconds after calculating total minutes and hours is 1. // e) What is the return value of pad when it is called for the last time in this program? Explain your answer // =============> write your answer here +// The return value of pad when it is called for the last time in this program is "01", which is the padded string representation of remainingSeconds (1) +// when the input is 61 seconds. \ No newline at end of file From 23a6152a8501609eb84a8e56a1dac678ee8d41c2 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Thu, 2 Jul 2026 01:40:05 +0200 Subject: [PATCH 4/8] completed format -time.js --- Sprint-2/5-stretch-extend/format-time.js | 79 +++++++++++++++++++++--- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..cdae172beb 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,25 +1,84 @@ // This is the latest solution to the problem from the prep. // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. - +; function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + if (h) + + if (hours === 0) { + return `12:${minutes} am`; + } + + if (hours === 12) { + return `12:${minutes} pm`; + } + if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${minutes} pm`; } + return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +// Existing tests +console.assert( + formatAs12HourClock("08:00") === "08:00 am", + "08:00 should be 08:00 am" +); + +console.assert( + formatAs12HourClock("23:00") === "11:00 pm", + "23:00 should be 11:00 pm" +); + +// Additional tests + +// Midnight console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + formatAs12HourClock("00:00") === "12:00 am", + "00:00 should be 12:00 am" ); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; +// Noon console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + formatAs12HourClock("12:00") === "12:00 pm", + "12:00 should be 12:00 pm" ); + +// PM with minutes +console.assert( + formatAs12HourClock("13:30") === "1:30 pm", + "13:30 should be 1:30 pm" +); + +// AM with minutes +console.assert( + formatAs12HourClock("09:45") === "09:45 am", + "09:45 should be 09:45 am" +); + +// Last minute of the day +console.assert( + formatAs12HourClock("23:59") === "11:59 pm", + "23:59 should be 11:59 pm" +); + +// One minute after midnight +console.assert( + formatAs12HourClock("00:01") === "12:01 am", + "00:01 should be 12:01 am" +); + +// One minute after noon +console.assert( + formatAs12HourClock("12:01") === "12:01 pm", + "12:01 should be 12:01 pm" +); + +// 1 PM +console.assert( + formatAs12HourClock("13:00") === "1:00 pm", + "13:00 should be 1:00 pm" +); \ No newline at end of file From 26dd684fa748fbfe8ad894c86917d5aa1b9b14d4 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Sat, 4 Jul 2026 13:25:06 +0200 Subject: [PATCH 5/8] corrected time formate --- Sprint-2/5-stretch-extend/format-time.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index cdae172beb..19162119b7 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -24,8 +24,8 @@ function formatAs12HourClock(time) { // Existing tests console.assert( - formatAs12HourClock("08:00") === "08:00 am", - "08:00 should be 08:00 am" + formatAs12HourClock("8:00") === "8:00 am", + "8:00 should be 8:00 am" ); console.assert( @@ -37,8 +37,8 @@ console.assert( // Midnight console.assert( - formatAs12HourClock("00:00") === "12:00 am", - "00:00 should be 12:00 am" + formatAs12HourClock("0:00") === "12:00 am", + "0:00 should be 12:00 am" ); // Noon @@ -55,8 +55,8 @@ console.assert( // AM with minutes console.assert( - formatAs12HourClock("09:45") === "09:45 am", - "09:45 should be 09:45 am" + formatAs12HourClock("9:45") === "9:45 am", + "9:45 should be 9:45 am" ); // Last minute of the day From bfe65da5d8c2510a91e9b41c7124cad74ed95272 Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Sat, 4 Jul 2026 13:51:51 +0200 Subject: [PATCH 6/8] completed errors --- Sprint-2/5-stretch-extend/format-time.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 19162119b7..6dda5f826b 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,9 +3,8 @@ // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. ; function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - const minutes = time.slice(3, 5); - if (h) + const [hourString, minutes] = time.split(":"); +const hours = Number(hourString); if (hours === 0) { return `12:${minutes} am`; @@ -15,11 +14,11 @@ function formatAs12HourClock(time) { return `12:${minutes} pm`; } - if (hours > 12) { - return `${hours - 12}:${minutes} pm`; + if (hours < 12) { + return `${hours}:${minutes} am`; } - return `${time} am`; + return `${hours - 12}:${minutes} pm`; } // Existing tests From 52936995d20d287c511f4f7acb93fb7702fb939d Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Sun, 5 Jul 2026 00:07:45 +0200 Subject: [PATCH 7/8] modified my answers from second sprint --- Sprint-2/2-mandatory-debug/0.js | 3 ++- Sprint-2/3-mandatory-implement/2-cases.js | 8 ++++---- Sprint-2/3-mandatory-implement/3-to-pounds.js | 18 +++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index a5bcb0e58b..d6851efd02 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -4,7 +4,7 @@ function multiply(a, b) { -concole.lpg( a* b); +concole.log( a* b); } @@ -18,5 +18,6 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); function multiply (a,b){ if (a===10 && b===32){ let result =a * b ; + return result; } } \ 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 b29ada0ce3..9ca430af7d 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -16,8 +16,8 @@ // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase function touppersneakers (input){ - return input.trim().replace(/\s+/g, "_").touppercase(); + return input.toUpperCase(); } -console.log(touppersneakers("hello there"));//Hello There -console.log(touppersneakers("lord of the rings")); // lord of the rings -console.log(touppersneakers("good morning")); // GOOD MORNING +console.log(touppersneakers("hello there").toUpperCase());//Hello There +console.log(touppersneakers("lord of the rings").toUpperCase()); // LORD_OF_THE_RINGS +console.log(touppersneakers("good morning").toUpperCase()); // GOOD MORNING diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index f6e12ba937..0a92ffd05e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -7,17 +7,17 @@ -function toSnakeCase(str) { - const pecestringwithouttrailingp = pencestring.substring(0,pencestring.length -1); - const padded penceNumberstring = pencestringWithoutTrailingP.padstart(3,"0"); - const pounds = paddedpenceNumberString.substring(0, paddedpencenumberstring.length-2); - const pencr= paddedpencenumberstring.substring(paddedpencenumberstring.length -2) - .padEnd(2,"0"); - return £${pounds}.${pence}`; +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"); + return `£${pounds}.${pence}`; } // test the function with different inputs -consloe.log(topounds("399p"), // £3.99 -4console.log(toPounds("9p")); // £0.09 +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("9p")); // £0.09 console.log(toPounds("99p")); // £0.99 console.log(toPounds("1234p")); // £12.34 From ca8d208ca9e7fb8056e69bdfc2866a884148197f Mon Sep 17 00:00:00 2001 From: Enice-Codes Date: Mon, 20 Jul 2026 20:52:51 +0200 Subject: [PATCH 8/8] made changes from these excercises --- Sprint-2/2-mandatory-debug/0.js | 27 ++++++------- Sprint-2/3-mandatory-implement/2-cases.js | 48 ++++++++++++++++++++--- Sprint-2/5-stretch-extend/format-time.js | 45 +++++++++++---------- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index d6851efd02..f5d40cfbf5 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,23 +1,20 @@ // Predict and explain first... // =============> write your prediction here -// I predict that the function expression will run a nerro because the are errors in the code .such as the concole.log in line 6. +// I predict that the code would fail because "console.log" was misplaced and +// also because console.log doesnt return an value to use elsewhere. -function multiply(a, b) { -concole.log( a* b); -} +// =============> write your explanation here -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log only prints to the console — it returns undefined. +// Since the template literal needs an actual value, the function +// must use "return" instead of relying on console.log. -// =============> write your explanation here -// console.log prints out information it does not return any varable to its function.hence the syntax error. -// console.log cant read unprovided information. -// Finally, correct the code to fix the problem // =============> write your new code here -function multiply (a,b){ - if (a===10 && b===32){ - let result =a * b ; - return result; - } -} \ No newline at end of file +function multiply(a, b) { + let result = a * b; + return result; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ 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 9ca430af7d..d35f9e04f3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -5,19 +5,55 @@ // Implement a function that: +function toUpperSnakeCase(input) { + return input.toUpperCase().split(" ").join("_"); +} + + // Given a string input like "hello there" // When we call this function with the input string // it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" +console.assert( + toUpperSnakeCase("hello there") === "HELLO_THERE", + '"hello there" should be "HELLO_THERE"' +); // Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" +console.assert( + toUpperSnakeCase("lord of the rings") === "LORD_OF_THE_RINGS", + '"lord of the rings" should be "LORD_OF_THE_RINGS"' +); + // 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 touppersneakers (input){ - return input.toUpperCase(); -} -console.log(touppersneakers("hello there").toUpperCase());//Hello There -console.log(touppersneakers("lord of the rings").toUpperCase()); // LORD_OF_THE_RINGS -console.log(touppersneakers("good morning").toUpperCase()); // GOOD MORNING +console.assert( + toUpperSnakeCase("good morning") === "GOOD_MORNING", + '"good morning" should be "GOOD_MORNING"' +); + +// Single word, no spaces at all +console.assert( + toUpperSnakeCase("single") === "SINGLE", + '"single" should be "SINGLE"' +); + +// Empty string +console.assert( + toUpperSnakeCase("") === "", + "empty string should stay empty" +); + +// Already-uppercase input +console.assert( + toUpperSnakeCase("already UPPER case") === "ALREADY_UPPER_CASE", + '"already UPPER case" should be "ALREADY_UPPER_CASE"' +); + +// Multiple consecutive spaces (each becomes its own underscore) +console.assert( + toUpperSnakeCase("multiple spaces") === "MULTIPLE___SPACES", + '"multiple spaces" should be "MULTIPLE___SPACES"' +); diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 6dda5f826b..8bb46098c3 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,10 +1,11 @@ // This is the latest solution to the problem from the prep. // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. -; function formatAs12HourClock(time) { const [hourString, minutes] = time.split(":"); -const hours = Number(hourString); + const hours = Number(hourString); + + const pad = (h) => String(h).padStart(2, "0"); if (hours === 0) { return `12:${minutes} am`; @@ -15,16 +16,16 @@ const hours = Number(hourString); } if (hours < 12) { - return `${hours}:${minutes} am`; + return `${pad(hours)}:${minutes} am`; } - return `${hours - 12}:${minutes} pm`; + return `${pad(hours - 12)}:${minutes} pm`; } -// Existing tests +// Existing tests (updated to expect zero-padded hours) console.assert( - formatAs12HourClock("8:00") === "8:00 am", - "8:00 should be 8:00 am" + formatAs12HourClock("08:00") === "08:00 am", + "08:00 should be 08:00 am" ); console.assert( @@ -32,12 +33,10 @@ console.assert( "23:00 should be 11:00 pm" ); -// Additional tests - // Midnight console.assert( - formatAs12HourClock("0:00") === "12:00 am", - "0:00 should be 12:00 am" + formatAs12HourClock("00:00") === "12:00 am", + "00:00 should be 12:00 am" ); // Noon @@ -46,16 +45,16 @@ console.assert( "12:00 should be 12:00 pm" ); -// PM with minutes +// PM with minutes, hour needs padding console.assert( - formatAs12HourClock("13:30") === "1:30 pm", - "13:30 should be 1:30 pm" + formatAs12HourClock("13:30") === "01:30 pm", + "13:30 should be 01:30 pm" ); -// AM with minutes +// AM with minutes, hour needs padding console.assert( - formatAs12HourClock("9:45") === "9:45 am", - "9:45 should be 9:45 am" + formatAs12HourClock("09:45") === "09:45 am", + "09:45 should be 09:45 am" ); // Last minute of the day @@ -76,8 +75,14 @@ console.assert( "12:01 should be 12:01 pm" ); -// 1 PM +// 1 PM, hour needs padding +console.assert( + formatAs12HourClock("13:00") === "01:00 pm", + "13:00 should be 01:00 pm" +); + +// 1 AM, hour needs padding console.assert( - formatAs12HourClock("13:00") === "1:00 pm", - "13:00 should be 1:00 pm" + formatAs12HourClock("01:00") === "01:00 am", + "01:00 should be 01:00 am" ); \ No newline at end of file