From 4c29df26e56f801cd5f73fdcf1ce5042ff571176 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Sat, 19 Sep 2026 16:19:35 +0100 Subject: [PATCH 01/14] Fix HTML doctype casing and add CSS styles for form layout --- Form-Controls/index.html | 2 +- Form-Controls/style.css | 79 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Form-Controls/style.css diff --git a/Form-Controls/index.html b/Form-Controls/index.html index 74b591ffc..e2ac38bba 100644 --- a/Form-Controls/index.html +++ b/Form-Controls/index.html @@ -1,4 +1,4 @@ - + diff --git a/Form-Controls/style.css b/Form-Controls/style.css new file mode 100644 index 000000000..a3ecf1c3d --- /dev/null +++ b/Form-Controls/style.css @@ -0,0 +1,79 @@ +body { + font-family: Arial, sans-serif; + background-color: #f2f2f2; + margin: 0; +} + +header { + background-color: #333; + color: white; + text-align: center; + padding: 20px; +} + +header h1 { + margin: 0; +} + +main { + max-width: 600px; + margin: 30px auto; + padding: 0 20px; +} + +fieldset { + background-color: white; + border: 1px solid #ccc; + border-radius: 8px; + padding: 20px; + margin-bottom: 20px; +} + +legend { + font-weight: bold; + padding: 0 20px; +} + +fieldset p { + margin-bottom: 15px; +} + +input[type="text"], +input[type="email"] { + display: block; + width: 100%; + box-sizing: border-box; + padding: 10px; + margin-top: 6px; + border: 1px solid #bbb; + border-radius: 5px; +} + +select { + display: block; + margin-top: 6px; + padding: 10px; + border: 1px solid #bbb; + border-radius: 5px; +} + +input[type="submit"] { + background-color: #bbb; + color: black; + font-weight: bold; + padding: 10px 20px; + border-radius: 5px; +} +input[type="text"]:focus, +input[type="email"]:focus, +input[type="radio"]:focus, +input[type="submit"]:focus, +select:focus { + outline: 3px solid black; +} + +footer { + font-weight: bold; + padding: 10px 20px; + margin-top: 6px; +} From 2a3a27d91ddcd6e0847775bc6dec302d585642dc Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Sat, 26 Sep 2026 00:12:27 +0100 Subject: [PATCH 02/14] Fix variable redeclaration error in capitalise function --- Sprint-3/1-key-errors/0.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..2f79eb019 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,22 @@ // Predict and explain first... -// =============> write your prediction here +// I am predicting the code will generate error because the variable str is declared twice // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +/*function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +console.log(capitalise("hello World"));*/ + +// After we run the code, it generated this error SyntaxError: Identifier str has already been declared +// This happened because we tried to declare again using the keyword let the variable str +// which was declared before in the parameter of the function -// =============> write your explanation here -// =============> write your new code here +//Here is the fixed code +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise("hello World")); From 4eaa3d3c34fb396902b7afb3a4eaae5c623943a9 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Sat, 26 Sep 2026 01:06:13 +0100 Subject: [PATCH 03/14] Fix variable redeclaration and update function call in percentage conversion --- Sprint-3/1-key-errors/1.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..5a8917385 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,32 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// I predict the code will generate 2 errors because one the variable decimalNumber is declared twice and two +// the function is not called instead the variable decimalNumber is called and it can't be accessed because +// it was declared locally as a parameter of the function // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +/*function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(decimalNumber);*/ -// =============> write your explanation here +// After we run the code, it generated an error SyntaxError: Identifier 'decimalNumber' has already been declared +// because we tried to declare decimalNumber again. After fixing this error again we got another error ReferenceError: decimalNumber is not defined +// because the decimalNumber is locally scoped, javascript can't access it when the function is called +// additionally the function was not called console.log(decimalNumber) this simply means print the value of decimalNumber // Finally, correct the code to fix the problem -// =============> write your new code here +// Here is the fixed code +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); From 47e6f25c0a240865eef34951a247f3134a536ed1 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Sat, 26 Sep 2026 01:15:09 +0100 Subject: [PATCH 04/14] Fix function parameter declaration and update error prediction comments --- Sprint-3/1-key-errors/2.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..d32330049 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,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 -// =============> write your prediction of the error here +// I predict the error will come from the argument because when we write a function we first declare parameters not values -function square(3) { +/*function square(3) { return num * num; -} +}*/ -// =============> write the error message here +// SyntaxError: Unexpected number -// =============> explain this error message here +// this error tells us javascript expects valid variable identifiers when function is defined not values // Finally, correct the code to fix the problem -// =============> write your new code here - - +// Here is the fixed code +function square(num) { + return num * num; +} +console.log(square(3)); From 1250064c3c984ea3d0148e6c8ecc8ae31469ad60 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 16:38:13 +0100 Subject: [PATCH 05/14] Explaning and fixing the bug by adding return keyword --- Sprint-3/2-mandatory-debug/0.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..47d9cc330 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,22 @@ // Predict and explain first... -// =============> write your prediction here +// I predict the code will run normally and print the result of a * b on the first console, but it will return undefined on the +// second console.log -function multiply(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 +// The reason for printing undefined is that we didn't define a return value so the js doesn't know what to return and it simply returns undefined +// We can fix the code by replacing the console.log with a return keyword so the js knows what to return when the function is called // Finally, correct the code to fix the problem -// =============> write your new code here +// Here is the fixed code + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From 0e0827d89d64c722f3d5e7693101f42ee53199eb Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 16:59:24 +0100 Subject: [PATCH 06/14] Explained and fixed the bug proper use of return statment --- Sprint-3/2-mandatory-debug/1.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..b6f9837ff 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,21 @@ // Predict and explain first... -// =============> write your prediction here +// I predict that the code will run but it will print undefined because the return expression is not setup properly -function sum(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)}`);*/ + +// When we run the code it printed out undefined because the return keyword is there but the expression that needs to be returned is not on the same line +// therefore the return keyword can't reach the expression and the expression is ignored because the function has done execution right after it reaches the return keyword -// =============> write your explanation here // Finally, correct the code to fix the problem -// =============> write your new code here +// Here is the fixed code + +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 8ad0bd9e64b7e4790ea93237f7b2ea1d9173b58f Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 17:25:54 +0100 Subject: [PATCH 07/14] Explaining and fixing the bug by adding parameter --- Sprint-3/2-mandatory-debug/2.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..f12c51adc 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -1,9 +1,9 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// I predict the code will run but will give us unexpected output as the function does not have parameter but we provided an argument -const num = 103; +/*const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -11,14 +11,26 @@ function getLastDigit() { 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 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 +// It is because we declared a function with no parameters so the function will ignore any arguments we provide +// since the var num is declared and assigned with a value so every time the function is called it will use the var num + // Finally, correct the code to fix the problem -// =============> write your new code here +// Here is the fixed code +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 92ecd918cd60e3b05b99534a9b45574cbaac3ee2 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 18:06:41 +0100 Subject: [PATCH 08/14] created a function that calculates BMI and returns string with one decimal point --- Sprint-3/3-mandatory-implement/1-bmi.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..a29c8593d 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,9 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + const BMI = weight / height ** 2; + const stringBMI = BMI.toString(); + return stringBMI.slice(0, stringBMI.indexOf(".") + 2); } + +console.log(calculateBMI(70, 1.73)); From 0fee2589328f9dd8316c2d5dc8e0657efa9511f1 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 18:38:27 +0100 Subject: [PATCH 09/14] creating a function that uppercases string and replace empty space --- Sprint-3/3-mandatory-implement/2-cases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..5975da6ac 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/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 uppercaseAndUnderscore(word) { + return word.toUpperCase().replaceAll(" ", "_"); +} +console.log(uppercaseAndUnderscore("welcome to cyf")); From 6e72bf1f67db4f3cf3a55debe6e49ea4dd41becc Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 22:46:29 +0100 Subject: [PATCH 10/14] implementing the function that changes different input in to pounds --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..1973cccd9 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,22 @@ // 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) { + if (penceString == "") { + return "please put the amount"; + } + const totalPence = parseInt(penceString, 10); + const pounds = totalPence / 100; + const formattedPound = pounds.toFixed(2); + return "£" + formattedPound; +} + +console.log(toPounds("1991p")); +console.log(toPounds("2020p")); +console.log(toPounds("399p")); +console.log(toPounds("69p")); +console.log(toPounds("00p ")); +console.log(toPounds(" 50p ")); +console.log(toPounds("232423")); +console.log(toPounds("")); From 481cdd21626ca5886ef040a83d710d3621ea69bd Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Mon, 28 Sep 2026 23:51:30 +0100 Subject: [PATCH 11/14] added explanation about the function call --- Sprint-3/4-mandatory-interpret/time-format.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..471be6c25 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -15,24 +15,29 @@ 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 +// The function pad will be called three 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 +// num is assigned value of totalHours when pad is called first time because js evaluates expressions from left to right // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// The return value will be "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 +// num will be assigned the value of remainingSeconds when pad is called for the last time because js evaluates any expression +// from left to right and the pad with argument remainingSeconds is found at the right end // 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 is "01" +// We calculated remainingSeconds in the function formatTimeDisplay and we got the value 1 then when pad is called with +// an argument value of remainingSeconds we changed the value to string and 0 is added before 1 and it became 2 digits which is "01" From 0d560fc02750704f8b7f0a9db474b8c000750e2b Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Wed, 30 Sep 2026 17:54:45 +0100 Subject: [PATCH 12/14] refactor formatAs12HourClock function to handle input validation and edge cases --- Sprint-3/5-stretch-extend/format-time.js | 97 +++++++++++++++++++++--- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 32a32e66b..11072b3e6 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -3,23 +3,98 @@ // 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)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const slicedHours = time.slice(0, 2); + const hours = Number(slicedHours); + const slicedMinutes = time.slice(-2); + const minutes = Number(slicedMinutes); + const pattern = /^\d{2}:\d{2}$/; + if (!pattern.test(time)) { + return `wrong format input`; + } + if (minutes < 60) { + if (hours >= 24) { + return `please check your input hour`; + } else if (hours > 12) { + return `${hours - 12}:${slicedMinutes} pm`; + } else if (hours === 0) { + return `12:${slicedMinutes} am`; + } else { + return `${slicedHours}:${slicedMinutes} am`; + } + } else { + return `please check your input minute`; } - return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +const currentOutput1 = formatAs12HourClock("00:60"); +const targetOutput1 = "please check your input minute"; console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + currentOutput1 === targetOutput1, + `current output: ${currentOutput1}, target output: ${targetOutput1}`, + "dude whats wrong", ); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; +const currentOutput2 = formatAs12HourClock("24:45"); +const targetOutput2 = "please check your input hour"; console.assert( currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + `current output: ${currentOutput2}, target output: ${targetOutput2}`, + "dude whats wrong", +); + +const currentOutput3 = formatAs12HourClock("23:59"); +const targetOutput3 = "11:59 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}`, + "dude whats wrong", +); + +const currentOutput4 = formatAs12HourClock("07:30"); +const targetOutput4 = "07:30 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}`, + "dude whats wrong", +); + +const currentOutput5 = formatAs12HourClock("22:45"); +const targetOutput5 = "10:45 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}`, + "dude whats wrong", ); + +const currentOutput6 = formatAs12HourClock("00:20"); +const targetOutput6 = "12:20 am"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}`, + "dude whats wrong", +); + +const currentOutput7 = formatAs12HourClock("12:45"); +const targetOutput7 = "12:45 pm"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}`, + "dude whats wrong", +); + +const currentOutput8 = formatAs12HourClock("00:0"); +const targetOutput8 = "wrong format input"; +console.assert( + currentOutput8 === targetOutput8, + `current output: ${currentOutput8}, target output: ${targetOutput8}`, + "dude whats wrong", +); + +console.log(formatAs12HourClock("00:60")); +console.log(formatAs12HourClock("24:45")); +console.log(formatAs12HourClock("23:59")); +console.log(formatAs12HourClock("07:30")); +console.log(formatAs12HourClock("22:45")); +console.log(formatAs12HourClock("00:20")); +console.log(formatAs12HourClock("12:45")); +console.log(formatAs12HourClock("00:0")); From 0f24ef2fdf3b66b6d01b25437fc7320d88b85205 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Wed, 30 Sep 2026 18:24:48 +0100 Subject: [PATCH 13/14] Complete Sprint-3 coursework --- Sprint-3/1-key-errors/0.js | 44 ++-- Sprint-3/1-key-errors/1.js | 64 +++--- Sprint-3/1-key-errors/2.js | 42 ++-- Sprint-3/2-mandatory-debug/0.js | 44 ++-- Sprint-3/2-mandatory-debug/1.js | 42 ++-- Sprint-3/2-mandatory-debug/2.js | 72 +++---- Sprint-3/3-mandatory-implement/1-bmi.js | 46 ++-- Sprint-3/3-mandatory-implement/2-cases.js | 40 ++-- Sprint-3/3-mandatory-implement/3-to-pounds.js | 50 ++--- Sprint-3/4-mandatory-interpret/time-format.js | 86 ++++---- Sprint-3/5-stretch-extend/format-time.js | 200 +++++++++--------- 11 files changed, 365 insertions(+), 365 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 2f79eb019..dd7dfa253 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,22 +1,22 @@ -// Predict and explain first... -// I am predicting the code will generate error because the variable str is declared twice - -// 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; -} -console.log(capitalise("hello World"));*/ - -// After we run the code, it generated this error SyntaxError: Identifier str has already been declared -// This happened because we tried to declare again using the keyword let the variable str -// which was declared before in the parameter of the function - -//Here is the fixed code -function capitalise(str) { - str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} -console.log(capitalise("hello World")); +// Predict and explain first... +// I am predicting the code will generate error because the variable str is declared twice + +// 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; +} +console.log(capitalise("hello World"));*/ + +// After we run the code, it generated this error SyntaxError: Identifier str has already been declared +// This happened because we tried to declare again using the keyword let the variable str +// which was declared before in the parameter of the function + +//Here is the fixed code +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise("hello World")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index 5a8917385..fd820ff79 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,32 +1,32 @@ -// Predict and explain first... - -// Why will an error occur when this program runs? -// I predict the code will generate 2 errors because one the variable decimalNumber is declared twice and two -// the function is not called instead the variable decimalNumber is called and it can't be accessed because -// it was declared locally as a parameter of the 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}%`; - - return percentage; -} - -console.log(decimalNumber);*/ - -// After we run the code, it generated an error SyntaxError: Identifier 'decimalNumber' has already been declared -// because we tried to declare decimalNumber again. After fixing this error again we got another error ReferenceError: decimalNumber is not defined -// because the decimalNumber is locally scoped, javascript can't access it when the function is called -// additionally the function was not called console.log(decimalNumber) this simply means print the value of decimalNumber - -// Finally, correct the code to fix the problem -// Here is the fixed code -function convertToPercentage(decimalNumber) { - const percentage = `${decimalNumber * 100}%`; - - return percentage; -} - -console.log(convertToPercentage(0.5)); +// Predict and explain first... + +// Why will an error occur when this program runs? +// I predict the code will generate 2 errors because one the variable decimalNumber is declared twice and two +// the function is not called instead the variable decimalNumber is called and it can't be accessed because +// it was declared locally as a parameter of the 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}%`; + + return percentage; +} + +console.log(decimalNumber);*/ + +// After we run the code, it generated an error SyntaxError: Identifier 'decimalNumber' has already been declared +// because we tried to declare decimalNumber again. After fixing this error again we got another error ReferenceError: decimalNumber is not defined +// because the decimalNumber is locally scoped, javascript can't access it when the function is called +// additionally the function was not called console.log(decimalNumber) this simply means print the value of decimalNumber + +// Finally, correct the code to fix the problem +// Here is the fixed code +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index d32330049..dfdb0d395 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,21 +1,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 - -// I predict the error will come from the argument because when we write a function we first declare parameters not values - -/*function square(3) { - return num * num; -}*/ - -// SyntaxError: Unexpected number - -// this error tells us javascript expects valid variable identifiers when function is defined not values - -// Finally, correct the code to fix the problem - -// Here is the fixed code -function square(num) { - return num * num; -} -console.log(square(3)); +// Predict and explain first BEFORE you run any code... + +// this function should square any number but instead we're going to get an error + +// I predict the error will come from the argument because when we write a function we first declare parameters not values + +/*function square(3) { + return num * num; +}*/ + +// SyntaxError: Unexpected number + +// this error tells us javascript expects valid variable identifiers when function is defined not values + +// Finally, correct the code to fix the problem + +// Here is the fixed code +function square(num) { + return num * num; +} +console.log(square(3)); diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index 47d9cc330..50c37d9ea 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,22 +1,22 @@ -// Predict and explain first... - -// I predict the code will run normally and print the result of a * b on the first console, but it will return undefined on the -// second console.log - -/*function multiply(a, b) { - console.log(a * b); -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/ - -// The reason for printing undefined is that we didn't define a return value so the js doesn't know what to return and it simply returns undefined -// We can fix the code by replacing the console.log with a return keyword so the js knows what to return when the function is called - -// Finally, correct the code to fix the problem -// Here is the fixed code - -function multiply(a, b) { - return a * b; -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// Predict and explain first... + +// I predict the code will run normally and print the result of a * b on the first console, but it will return undefined on the +// second console.log + +/*function multiply(a, b) { + console.log(a * b); +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/ + +// The reason for printing undefined is that we didn't define a return value so the js doesn't know what to return and it simply returns undefined +// We can fix the code by replacing the console.log with a return keyword so the js knows what to return when the function is called + +// Finally, correct the code to fix the problem +// Here is the fixed code + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index b6f9837ff..d5c63b0e5 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,21 +1,21 @@ -// Predict and explain first... -// I predict that the code will run but it will print undefined because the return expression is not setup properly - -/*function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ - -// When we run the code it printed out undefined because the return keyword is there but the expression that needs to be returned is not on the same line -// therefore the return keyword can't reach the expression and the expression is ignored because the function has done execution right after it reaches the return keyword - -// Finally, correct the code to fix the problem -// Here is the fixed code - -function sum(a, b) { - return a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// Predict and explain first... +// I predict that the code will run but it will print undefined because the return expression is not setup properly + +/*function sum(a, b) { + return; + a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ + +// When we run the code it printed out undefined because the return keyword is there but the expression that needs to be returned is not on the same line +// therefore the return keyword can't reach the expression and the expression is ignored because the function has done execution right after it reaches the return keyword + +// Finally, correct the code to fix the problem +// Here is the fixed code + +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index f12c51adc..d3eff7d84 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -1,36 +1,36 @@ -// Predict and explain first... - -// Predict the output of the following code: -// I predict the code will run but will give us unexpected output as the function does not have parameter but we provided an argument - -/*const num = 103; - -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 -// 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 -// It is because we declared a function with no parameters so the function will ignore any arguments we provide -// since the var num is declared and assigned with a value so every time the function is called it will use the var num - -// Finally, correct the code to fix the problem -// Here is the fixed code -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 +// Predict and explain first... + +// Predict the output of the following code: +// I predict the code will run but will give us unexpected output as the function does not have parameter but we provided an argument + +/*const num = 103; + +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 +// 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 +// It is because we declared a function with no parameters so the function will ignore any arguments we provide +// since the var num is declared and assigned with a value so every time the function is called it will use the var num + +// Finally, correct the code to fix the problem +// Here is the fixed code +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 diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index a29c8593d..b95e97ba2 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -1,23 +1,23 @@ -// Below are the steps for how BMI is calculated - -// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. - -// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: - -// squaring your height: 1.73 x 1.73 = 2.99 -// dividing 70 by 2.99 = 23.41 -// Your result will be displayed to 1 decimal place, for example '23.4'. - -// You will need to implement a function that calculates the BMI of someone based off their weight and height - -// Given someone's weight in kg and height in metres -// Then when we call this function with the weight and height -// It should return a string of their Body Mass Index to 1 decimal place - -function calculateBMI(weight, height) { - const BMI = weight / height ** 2; - const stringBMI = BMI.toString(); - return stringBMI.slice(0, stringBMI.indexOf(".") + 2); -} - -console.log(calculateBMI(70, 1.73)); +// Below are the steps for how BMI is calculated + +// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. + +// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: + +// squaring your height: 1.73 x 1.73 = 2.99 +// dividing 70 by 2.99 = 23.41 +// Your result will be displayed to 1 decimal place, for example '23.4'. + +// You will need to implement a function that calculates the BMI of someone based off their weight and height + +// Given someone's weight in kg and height in metres +// Then when we call this function with the weight and height +// It should return a string of their Body Mass Index to 1 decimal place + +function calculateBMI(weight, height) { + const BMI = weight / height ** 2; + const stringBMI = BMI.toString(); + return stringBMI.slice(0, stringBMI.indexOf(".") + 2); +} + +console.log(calculateBMI(70, 1.73)); diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5975da6ac..c820144df 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -1,20 +1,20 @@ -// A set of words can be grouped together in different cases. - -// For example, "hello there" in snake case would be written "hello_there" -// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. - -// Implement a function that: - -// 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" - -// Another example: "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 uppercaseAndUnderscore(word) { - return word.toUpperCase().replaceAll(" ", "_"); -} -console.log(uppercaseAndUnderscore("welcome to cyf")); +// A set of words can be grouped together in different cases. + +// For example, "hello there" in snake case would be written "hello_there" +// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. + +// Implement a function that: + +// 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" + +// Another example: "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 uppercaseAndUnderscore(word) { + return word.toUpperCase().replaceAll(" ", "_"); +} +console.log(uppercaseAndUnderscore("welcome to cyf")); diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 1973cccd9..000b99a2d 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -1,25 +1,25 @@ -// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js - -// You will need to take this code and turn it into a reusable block of code. -// 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) { - if (penceString == "") { - return "please put the amount"; - } - const totalPence = parseInt(penceString, 10); - const pounds = totalPence / 100; - const formattedPound = pounds.toFixed(2); - return "£" + formattedPound; -} - -console.log(toPounds("1991p")); -console.log(toPounds("2020p")); -console.log(toPounds("399p")); -console.log(toPounds("69p")); -console.log(toPounds("00p ")); -console.log(toPounds(" 50p ")); -console.log(toPounds("232423")); -console.log(toPounds("")); +// In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js + +// You will need to take this code and turn it into a reusable block of code. +// 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) { + if (penceString == "") { + return "please put the amount"; + } + const totalPence = parseInt(penceString, 10); + const pounds = totalPence / 100; + const formattedPound = pounds.toFixed(2); + return "£" + formattedPound; +} + +console.log(toPounds("1991p")); +console.log(toPounds("2020p")); +console.log(toPounds("399p")); +console.log(toPounds("69p")); +console.log(toPounds("00p ")); +console.log(toPounds(" 50p ")); +console.log(toPounds("232423")); +console.log(toPounds("")); diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index 471be6c25..6ee095562 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -1,43 +1,43 @@ -function pad(num) { - let numString = num.toString(); - while (numString.length < 2) { - numString = "0" + numString; - } - return numString; -} - -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; - - 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? -// The function pad will be called three 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? -// num is assigned value of totalHours when pad is called first time because js evaluates expressions from left to right - -// c) What is the return value of pad when it is called for the first time? -// The return value will be "00" - -// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// num will be assigned the value of remainingSeconds when pad is called for the last time because js evaluates any expression -// from left to right and the pad with argument remainingSeconds is found at the right end - -// e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// The return value of pad when it is called for the last time is "01" -// We calculated remainingSeconds in the function formatTimeDisplay and we got the value 1 then when pad is called with -// an argument value of remainingSeconds we changed the value to string and 0 is added before 1 and it became 2 digits which is "01" +function pad(num) { + let numString = num.toString(); + while (numString.length < 2) { + numString = "0" + numString; + } + return numString; +} + +function formatTimeDisplay(seconds) { + const remainingSeconds = seconds % 60; + const totalMinutes = (seconds - remainingSeconds) / 60; + const remainingMinutes = totalMinutes % 60; + const totalHours = (totalMinutes - remainingMinutes) / 60; + + 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? +// The function pad will be called three 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? +// num is assigned value of totalHours when pad is called first time because js evaluates expressions from left to right + +// c) What is the return value of pad when it is called for the first time? +// The return value will be "00" + +// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer +// num will be assigned the value of remainingSeconds when pad is called for the last time because js evaluates any expression +// from left to right and the pad with argument remainingSeconds is found at the right end + +// e) What is the return value of pad when it is called for the last time in this program? Explain your answer +// The return value of pad when it is called for the last time is "01" +// We calculated remainingSeconds in the function formatTimeDisplay and we got the value 1 then when pad is called with +// an argument value of remainingSeconds we changed the value to string and 0 is added before 1 and it became 2 digits which is "01" diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 11072b3e6..4c7f4ae60 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -1,100 +1,100 @@ -// 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 slicedHours = time.slice(0, 2); - const hours = Number(slicedHours); - const slicedMinutes = time.slice(-2); - const minutes = Number(slicedMinutes); - const pattern = /^\d{2}:\d{2}$/; - if (!pattern.test(time)) { - return `wrong format input`; - } - if (minutes < 60) { - if (hours >= 24) { - return `please check your input hour`; - } else if (hours > 12) { - return `${hours - 12}:${slicedMinutes} pm`; - } else if (hours === 0) { - return `12:${slicedMinutes} am`; - } else { - return `${slicedHours}:${slicedMinutes} am`; - } - } else { - return `please check your input minute`; - } -} - -const currentOutput1 = formatAs12HourClock("00:60"); -const targetOutput1 = "please check your input minute"; -console.assert( - currentOutput1 === targetOutput1, - `current output: ${currentOutput1}, target output: ${targetOutput1}`, - "dude whats wrong", -); - -const currentOutput2 = formatAs12HourClock("24:45"); -const targetOutput2 = "please check your input hour"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}`, - "dude whats wrong", -); - -const currentOutput3 = formatAs12HourClock("23:59"); -const targetOutput3 = "11:59 pm"; -console.assert( - currentOutput3 === targetOutput3, - `current output: ${currentOutput3}, target output: ${targetOutput3}`, - "dude whats wrong", -); - -const currentOutput4 = formatAs12HourClock("07:30"); -const targetOutput4 = "07:30 am"; -console.assert( - currentOutput4 === targetOutput4, - `current output: ${currentOutput4}, target output: ${targetOutput4}`, - "dude whats wrong", -); - -const currentOutput5 = formatAs12HourClock("22:45"); -const targetOutput5 = "10:45 pm"; -console.assert( - currentOutput5 === targetOutput5, - `current output: ${currentOutput5}, target output: ${targetOutput5}`, - "dude whats wrong", -); - -const currentOutput6 = formatAs12HourClock("00:20"); -const targetOutput6 = "12:20 am"; -console.assert( - currentOutput6 === targetOutput6, - `current output: ${currentOutput6}, target output: ${targetOutput6}`, - "dude whats wrong", -); - -const currentOutput7 = formatAs12HourClock("12:45"); -const targetOutput7 = "12:45 pm"; -console.assert( - currentOutput7 === targetOutput7, - `current output: ${currentOutput7}, target output: ${targetOutput7}`, - "dude whats wrong", -); - -const currentOutput8 = formatAs12HourClock("00:0"); -const targetOutput8 = "wrong format input"; -console.assert( - currentOutput8 === targetOutput8, - `current output: ${currentOutput8}, target output: ${targetOutput8}`, - "dude whats wrong", -); - -console.log(formatAs12HourClock("00:60")); -console.log(formatAs12HourClock("24:45")); -console.log(formatAs12HourClock("23:59")); -console.log(formatAs12HourClock("07:30")); -console.log(formatAs12HourClock("22:45")); -console.log(formatAs12HourClock("00:20")); -console.log(formatAs12HourClock("12:45")); -console.log(formatAs12HourClock("00:0")); +// 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 slicedHours = time.slice(0, 2); + const hours = Number(slicedHours); + const slicedMinutes = time.slice(-2); + const minutes = Number(slicedMinutes); + const pattern = /^\d{2}:\d{2}$/; + if (!pattern.test(time)) { + return `wrong format input`; + } + if (minutes < 60) { + if (hours >= 24) { + return `please check your input hour`; + } else if (hours > 12) { + return `${hours - 12}:${slicedMinutes} pm`; + } else if (hours === 0) { + return `12:${slicedMinutes} am`; + } else { + return `${slicedHours}:${slicedMinutes} am`; + } + } else { + return `please check your input minute`; + } +} + +const currentOutput1 = formatAs12HourClock("00:60"); +const targetOutput1 = "please check your input minute"; +console.assert( + currentOutput1 === targetOutput1, + `current output: ${currentOutput1}, target output: ${targetOutput1}`, + "dude whats wrong", +); + +const currentOutput2 = formatAs12HourClock("24:45"); +const targetOutput2 = "please check your input hour"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}`, + "dude whats wrong", +); + +const currentOutput3 = formatAs12HourClock("23:59"); +const targetOutput3 = "11:59 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}`, + "dude whats wrong", +); + +const currentOutput4 = formatAs12HourClock("07:30"); +const targetOutput4 = "07:30 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}`, + "dude whats wrong", +); + +const currentOutput5 = formatAs12HourClock("22:45"); +const targetOutput5 = "10:45 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}`, + "dude whats wrong", +); + +const currentOutput6 = formatAs12HourClock("00:20"); +const targetOutput6 = "12:20 am"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}`, + "dude whats wrong", +); + +const currentOutput7 = formatAs12HourClock("12:45"); +const targetOutput7 = "12:45 pm"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}`, + "dude whats wrong", +); + +const currentOutput8 = formatAs12HourClock("00:0"); +const targetOutput8 = "wrong format input"; +console.assert( + currentOutput8 === targetOutput8, + `current output: ${currentOutput8}, target output: ${targetOutput8}`, + "dude whats wrong", +); + +console.log(formatAs12HourClock("00:60")); +console.log(formatAs12HourClock("24:45")); +console.log(formatAs12HourClock("23:59")); +console.log(formatAs12HourClock("07:30")); +console.log(formatAs12HourClock("22:45")); +console.log(formatAs12HourClock("00:20")); +console.log(formatAs12HourClock("12:45")); +console.log(formatAs12HourClock("00:0")); From a630a94f90ef4f44f53358826b04fe5d9c949b63 Mon Sep 17 00:00:00 2001 From: Aklilu Mihtsun Date: Thu, 1 Oct 2026 11:39:05 +0100 Subject: [PATCH 14/14] removing the html and css files from coursework/sprint-3 branch --- Form-Controls/index.html | 2 +- Form-Controls/style.css | 79 ---------------------------------------- 2 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 Form-Controls/style.css diff --git a/Form-Controls/index.html b/Form-Controls/index.html index e2ac38bba..74b591ffc 100644 --- a/Form-Controls/index.html +++ b/Form-Controls/index.html @@ -1,4 +1,4 @@ - + diff --git a/Form-Controls/style.css b/Form-Controls/style.css deleted file mode 100644 index a3ecf1c3d..000000000 --- a/Form-Controls/style.css +++ /dev/null @@ -1,79 +0,0 @@ -body { - font-family: Arial, sans-serif; - background-color: #f2f2f2; - margin: 0; -} - -header { - background-color: #333; - color: white; - text-align: center; - padding: 20px; -} - -header h1 { - margin: 0; -} - -main { - max-width: 600px; - margin: 30px auto; - padding: 0 20px; -} - -fieldset { - background-color: white; - border: 1px solid #ccc; - border-radius: 8px; - padding: 20px; - margin-bottom: 20px; -} - -legend { - font-weight: bold; - padding: 0 20px; -} - -fieldset p { - margin-bottom: 15px; -} - -input[type="text"], -input[type="email"] { - display: block; - width: 100%; - box-sizing: border-box; - padding: 10px; - margin-top: 6px; - border: 1px solid #bbb; - border-radius: 5px; -} - -select { - display: block; - margin-top: 6px; - padding: 10px; - border: 1px solid #bbb; - border-radius: 5px; -} - -input[type="submit"] { - background-color: #bbb; - color: black; - font-weight: bold; - padding: 10px 20px; - border-radius: 5px; -} -input[type="text"]:focus, -input[type="email"]:focus, -input[type="radio"]:focus, -input[type="submit"]:focus, -select:focus { - outline: 3px solid black; -} - -footer { - font-weight: bold; - padding: 10px 20px; - margin-top: 6px; -}