From bb20b652f6e4561e9cc731732d71562e855b391e Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Tue, 9 Dec 2025 11:49:35 +0100 Subject: [PATCH 01/11] Added key-errors/0.js file solution. --- Sprint-2/1-key-errors/0.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..1d4b725cd1 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,31 @@ // Predict and explain first... // =============> write your prediction here +// +// We'll get syntax error with variable declaration. Function already have +// the variable str as a parameter. Then we try to declare another variable with +// the same name in the function body. // 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; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } +// +// capitalise("module structuring and testing data"); // =============> write your explanation here +// +// As predicted we cath error 'SyntaxError: Identifier 'str' has already been declared' +// // =============> write your new code here + +function capitalise(str) { + let resultStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return resultStr; +} + +console.log(capitalise("module structuring and testing data")); + + From 76fa5f1b273153996ab0521414754de844795c45 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Tue, 9 Dec 2025 12:08:34 +0100 Subject: [PATCH 02/11] Added key errors 1.js file solution. --- Sprint-2/1-key-errors/1.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..c4cd145349 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,39 @@ // Why will an error occur when this program runs? // =============> write your prediction here - +// +// We'll get a syntax error with redeclaration of the exist variable. The variable +// decimalNumber is already declared as a parameter of the function, but then we +// try to declare and initialize new constant with the same name. Other problem +// is that we try to use in the console.log() function invocation variable declared +// inside the function and don't accessible from global scope. +// // 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); + +// =============> write your explanation here +// +// As predicted we got an error 'SyntaxError: Identifier 'decimalNumber' has +// already been declared'. But solution depends of logic of the function. +// +// Finally, correct the code to fix the problem +// =============> write your new code here + +const decimalNumber = 0.5; + function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } console.log(decimalNumber); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here +console.log(convertToPercentage(decimalNumber)); \ No newline at end of file From 86d35f882a369f099a5ca7f6731cef0e3b96d8e0 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Tue, 9 Dec 2025 12:19:44 +0100 Subject: [PATCH 03/11] Added key errors 2.js file solution. --- Sprint-2/1-key-errors/2.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..cc3c0fc0b6 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,31 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// +// We have function declaration errors: +// 1. Instead of a parameter there is an numeric value in the function signature +// 2. We try to use undeclared variable num in the body of the function. -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here - +// +// SyntaxError: Unexpected number +// // =============> explain this error message here - +// +// As predicted error is a numeric literal instead of the function parameter. +// // Finally, correct the code to fix the problem - +// +// We need to change the number 3 with name of variable is used in function +// // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)); \ No newline at end of file From 78c435f05aa496f40e17bc3dd4f38376a74d8d2c Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 11:45:03 +0100 Subject: [PATCH 04/11] Added sprint 2 mandatory debug 0.js file solution. --- Sprint-2/2-mandatory-debug/0.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..7749ea7451 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,13 +2,28 @@ // =============> write your prediction here -function multiply(a, b) { - console.log(a * b); -} +// In function multiply first will be evaluated the multiply expression in parentheses. +// Then the received value will be printed in the console. So as result of running code +// we'll get result output: +// 320 +// The result of multiplying 10 and 32 is undefined -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// function multiply(a, b) { +// console.log(a * b); +// } + +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The multiply(a, b) function doesn't have a return value. So every time we run +// it we'll get undefined as a return 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)}`); From 948aa5bfedabd15113fbadb0ff71c7157a1e440b Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 11:56:58 +0100 Subject: [PATCH 05/11] Added mandatory debug 1.js file solution. --- Sprint-2/2-mandatory-debug/1.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..2dd362d048 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,27 @@ // Predict and explain first... // =============> write your prediction here -function sum(a, b) { - return; - a + b; -} +// As the result of function's work we'll get undefined value. So th code running +// result will look like: +// The sum of 10 and 32 is undefined + +// 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 + +// It happens because function's return statement stands before summing expression +// and return as function's work result undefined value. + // 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 512d5ad48a0f136b76ab925958f4a66d74836e8b Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 12:14:11 +0100 Subject: [PATCH 06/11] Added sprint 2 mandatory debug 2.js solution --- Sprint-2/2-mandatory-debug/2.js | 38 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..d2627ff6fe 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -3,22 +3,46 @@ // Predict the output of the following code: // =============> Write your prediction here -const num = 103; +// The output will looks lke: +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 -function getLastDigit() { - return num.toString().slice(-1); -} +// const num = 103; -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +// function getLastDigit() { +// return num.toString().slice(-1); +// } + +// console.log(`The last digit of 42 is ${getLastDigit(42)}`); +// console.log(`The last digit of 105 is ${getLastDigit(105)}`); +// console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction // =============> write the output here + +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 + // Explain why the output is the way it is // =============> write your explanation here + +// The given function doesn't have arguments and every time operate with variable +// num that is declared as global and is initialized with value 103. + // 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 bab0b6b19d143e167d8e3ab89477ebea8a145162 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 22:14:20 +0100 Subject: [PATCH 07/11] Added sprin 2 mandatory implement 1-bmi.js solution. --- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..c09c614d4a 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,5 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + return (weight / Math.pow(height, 2)).toFixed(1); } \ No newline at end of file From aec8c900a6dbe151fa53b4d57816af701de86521 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 22:22:37 +0100 Subject: [PATCH 08/11] Added sprint 2 mandatory implement 2-cases.js solution. --- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..029a0ba375 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 toUpperSnakeCase(str) { + return str.toUpperCase().replaceAll(' ', '_'); +} \ No newline at end of file From 6786b402c9600431c90285b01b1a56d9bd9179f8 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Wed, 10 Dec 2025 22:56:18 +0100 Subject: [PATCH 09/11] Aded sprint 2 mandatory implement 3-to-pounds.js file solution. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..f2cc32b1ea 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,86 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +function toPounds(penceString) { + const paddedPenceNumberString = penceString.substring(0, penceString.length - 1).padStart(3, '0'); + + return `£${paddedPenceNumberString.substring(0, paddedPenceNumberString.length -2)}.${ + paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, '0')}`; +} + +let currentOutput = toPounds("0p"); +let targetOutput = '£0.00'; +console.assert(currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +) + +currentOutput = toPounds("3p"); +targetOutput = "£0.03"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("20p"); +targetOutput = "£0.20"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("99p"); +targetOutput = "£0.99"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("100p"); +targetOutput = "£1.00"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("101p"); +targetOutput = "£1.01"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("120p"); +targetOutput = "£1.20"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("543p"); +targetOutput = "£5.43"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("999p"); +targetOutput = "£9.99"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("1000p"); +targetOutput = "£10.00"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); + +currentOutput = toPounds("1001p"); +targetOutput = "£10.01"; +console.assert( + currentOutput === targetOutput, + `Current output: '${currentOutput}', target output '${targetOutput}'` +); \ No newline at end of file From 6ade52f332ad459eaabca0013247bbbdac522191 Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Sat, 13 Dec 2025 17:36:41 +0100 Subject: [PATCH 10/11] Addes answers in mandatory interpres time-format.js file. --- Sprint-2/4-mandatory-interpret/time-format.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..f531a1620e 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -19,16 +19,32 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// The function pad(num) will be called 3 times in line 11. + + // Call formatTimeDisplay with an input of 61, now answer the following: +formatTimeDisplay(61); + // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here +// num = 1; + + // c) What is the return value of pad is called for the first time? // =============> write your answer here +// return value = '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 = 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 + +// return value == '01' \ No newline at end of file From 32b835a4e2582576baaf1d870a8bc8539db2855e Mon Sep 17 00:00:00 2001 From: Nikolai Romanov Date: Sat, 13 Dec 2025 18:08:46 +0100 Subject: [PATCH 11/11] Added tests and updated formatAs12HourClock(time) function logic in sprint 2 stretch-extended format-time.js file. --- Sprint-2/5-stretch-extend/format-time.js | 55 +++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..6ca04c0dfa 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,11 +1,15 @@ // 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 padTime(num) { + return num.toString().padStart(2, '0'); +} function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = Number(time.slice(3)); if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${padTime(hours - 12)}:${padTime(minutes)} pm`; } return `${time} am`; } @@ -23,3 +27,52 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("16:00"); +const targetOutput3 = "04:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("16:08"); +const targetOutput4 = "04:08 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("16:30"); +const targetOutput5 = "04:30 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); + +const currentOutput6 = formatAs12HourClock("08:08"); +const targetOutput6 = "08:08 am"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}` +); + +const currentOutput7 = formatAs12HourClock("08:38"); +const targetOutput7 = "08:38 am"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}` +); + +const currentOutput8 = formatAs12HourClock("00:00"); +const targetOutput8 = "00:00 am"; +console.assert( + currentOutput8 === targetOutput8, + `current output: ${currentOutput8}, target output: ${targetOutput8}` +); + +const currentOutput9 = formatAs12HourClock("23:59"); +const targetOutput9 = "11:59 pm"; +console.assert( + currentOutput9 === targetOutput9, + `current output: ${currentOutput9}, target output: ${targetOutput9}` +); \ No newline at end of file