From a4a9c1d593985126a64d368cb7b0ba018ae12197 Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Fri, 27 Jun 2025 21:26:55 +0100 Subject: [PATCH 01/15] Fix variable redeclaration in capitalise function --- Sprint-2/1-key-errors/0.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..9048e8cd7 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,5 +9,17 @@ function capitalise(str) { return str; } +//because str is already existing parameter we can not declare let str again. +// we can rename the str to fix the problem. + + +function capitalise(str) { + let cap_str = `${str[0].toUpperCase()}${str.slice(1)}`; + return cap_str; +} + +console.log(capitalise("khilola")); + + // =============> write your explanation here // =============> write your new code here From dcd31530f126156cc2aa305c68c02aac7930294a Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Fri, 27 Jun 2025 22:16:59 +0100 Subject: [PATCH 02/15] fixed error on converting to percentage --- Sprint-2/1-key-errors/1.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..10380e641 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -15,6 +15,16 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here +// decimalNumber is already a function parameter, so it's already declared in the function's scope. + + // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(50); \ No newline at end of file From 4af13ebe20c72a11c289c68cbad4dfd852e6d391 Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Fri, 27 Jun 2025 23:35:11 +0100 Subject: [PATCH 03/15] function square fixed --- Sprint-2/1-key-errors/2.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..fd430845c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,24 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here function square(3) { return num * num; } // =============> write the error message here +Function square(3) // =============> explain this error message here - +// 3 is not approprate parametr name. +// num is not defined, // Finally, correct the code to fix the problem // =============> write your new code here + function square(num) + return num*num + + console.log(square(3)); From de538089eb99663197b3052d02904e976a09ffc8 Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Fri, 27 Jun 2025 23:53:55 +0100 Subject: [PATCH 04/15] fixed the multiplication problem --- Sprint-2/2-mandatory-debug/0.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..f89c4426a 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -12,3 +12,8 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // 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)}`); \ No newline at end of file From af03c01488fe55b7f30b100c0ca9e1c43f290549 Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Sat, 28 Jun 2025 00:06:21 +0100 Subject: [PATCH 05/15] fixed the sum problem. --- Sprint-2/2-mandatory-debug/1.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..912914af6 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -9,5 +9,13 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +//The return; statement ends the function immediately. +//The next line (a + b;) is never executed because it's after the return and on a new line. // 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)}`); From 3f2bd6bf34fd6395ac208fdda6c074074b9cf98b Mon Sep 17 00:00:00 2001 From: Hilolarustam Date: Sat, 28 Jun 2025 00:16:06 +0100 Subject: [PATCH 06/15] last digit problem solved --- Sprint-2/2-mandatory-debug/2.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..51eb80f96 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -14,11 +14,23 @@ 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 +// =============> write the output here +//every time we run it we will get same answer 3 + // Explain why the output is the way it is // =============> write your explanation here + //it will only use global num=103 + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From f1b947f220d3da51a95ceda65259e3e8e98d6743 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Mon, 30 Jun 2025 16:19:37 +0100 Subject: [PATCH 07/15] BMI calculation --- Sprint-2/3-mandatory-implement/1-bmi.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..b706dfc4a 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,16 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file +} + + +function calculateBMI(weight, height) { + const bmi = weight / (height * height); //calculates the BMI + return parseFloat(bmi.toFixed(1)); // to ensure the result is rounded to 1 decimal place. +}// parselFloat converts the result back to a number from string. + + +console.log(calculateBMI(70, 1.73)); + +// + From d0529d8eec96ca5d98a6d5147332dd489fab12b3 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Mon, 30 Jun 2025 17:42:37 +0100 Subject: [PATCH 08/15] change to upper case --- Sprint-2/3-mandatory-implement/2-cases.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..24a2dff3a 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 + + +const greating = "Hello there" +console.log (greating.toUpperCase()); + +const heading = "lord of the rings" +console.log(heading.toUpperCase()); \ No newline at end of file From 681953ad8725fd5928439ccd8074dc5fa563f64b Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Mon, 30 Jun 2025 20:18:51 +0100 Subject: [PATCH 09/15] from topence toPounds --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..d5b79d902 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,25 @@ // 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 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}`; +} + +// checking with different inputs + +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("7p")); // £0.07 +console.log(toPounds("62p")); // £0.62 +console.log(toPounds("400p")); // £4.00 +console.log(toPounds("3p")); // £0.03 \ No newline at end of file From 7d8c6cf8a3db27f73e9fa6c37ec26a93d99331db Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Mon, 30 Jun 2025 20:56:28 +0100 Subject: [PATCH 10/15] formating time display --- Sprint-2/4-mandatory-interpret/time-format.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..bac9c1fe8 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// pad is going to be called 3 times. for hours, minutes and seconds // 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 +// 0 because 61 seconds is less then hours // c) What is the return value of pad is called for the first time? // =============> write your answer here +//"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 +// 1 last call as 61%60= 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 +//"01" because pad(1) - "1".padStart(2,"0")-"01" \ No newline at end of file From 5621c9c6e2a6fb20699d247c703bee9ba9f20ff9 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Mon, 30 Jun 2025 21:42:57 +0100 Subject: [PATCH 11/15] fixing bugs format time --- Sprint-2/5-stretch-extend/format-time.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..732fdcdce 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -5,7 +5,8 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:00 pm`; //This hardcodes :00, losing the original minutes from the time input. + //Even original minutes aren't 00 it will always return :00 } return `${time} am`; } @@ -23,3 +24,14 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +function formatAs12HourClock(time) { + const [hourStr, minute] = time.split(":"); + const hours = Number(hourStr); + + const isPM = hours >= 12; + const displayHour = hours % 12 === 0 ? 12 : hours % 12; + const suffix = isPM ? "pm" : "am"; + + return `${String(displayHour).padStart(2, "0")}:${minute} ${suffix}`; +} \ No newline at end of file From 587495b502ed03653e42d0e4bc6a95b598ee3ab8 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Wed, 2 Jul 2025 12:08:11 +0100 Subject: [PATCH 12/15] added predictions --- Sprint-2/1-key-errors/2.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index fd430845c..efb489e6e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,12 +5,21 @@ // =============> write your prediction of the error here +// =============> the parameter can not be a number +// Valid JavaScript Identifiers +// Must start with a letter (a-z, A-Z), underscore (_), or dollar sign ($). +// Cannot start with a number (0-9). +// Can contain letters, numbers, underscores, or dollar signs after the first character. +// Cannot be a reserved keyword (e.g., if, else, function, return). + + + function square(3) { return num * num; } // =============> write the error message here -Function square(3) +// function square(3) {return num * num } // =============> explain this error message here // 3 is not approprate parametr name. @@ -18,9 +27,10 @@ Function square(3) // Finally, correct the code to fix the problem // =============> write your new code here - function square(num) - return num*num + //function square(num){ + //return num*num ; + //} - console.log(square(3)); + //console.log(square(4)); From 853b42ea308cb777c6c7bc82f0c219ff7ea4c15f Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Wed, 2 Jul 2025 12:08:48 +0100 Subject: [PATCH 13/15] fixed the code --- Sprint-2/3-mandatory-implement/2-cases.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 24a2dff3a..a6612a87f 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -15,9 +15,8 @@ // 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 - -const greating = "Hello there" -console.log (greating.toUpperCase()); - -const heading = "lord of the rings" -console.log(heading.toUpperCase()); \ No newline at end of file +function toUpperSnakeCase (inputString) { + return inputString.toUpperCase().replaceAll(" ", "_"); +} +console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE" +console.log(toUpperSnakeCase("lord of the rings")); //"LORD_OF_THE_RINGS" \ No newline at end of file From 12485f98000974a42f7a0141d7f90f6c6db2f3c5 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Wed, 2 Jul 2025 12:38:34 +0100 Subject: [PATCH 14/15] on the prosses --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 732fdcdce..5af1ae79a 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -14,7 +14,7 @@ function formatAs12HourClock(time) { const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( - currentOutput === targetOutput, + formatAs12HourClock("08:00") === "08:00 am", `current output: ${currentOutput}, target output: ${targetOutput}` ); From 676d26f294d7d4979c5971724eb17cc413bf374f Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Wed, 2 Jul 2025 13:43:26 +0100 Subject: [PATCH 15/15] test added --- Sprint-2/5-stretch-extend/format-time.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 5af1ae79a..0c9763cf8 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -14,7 +14,7 @@ function formatAs12HourClock(time) { const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( - formatAs12HourClock("08:00") === "08:00 am", + currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); @@ -25,6 +25,7 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); +// new fixed code function formatAs12HourClock(time) { const [hourStr, minute] = time.split(":"); const hours = Number(hourStr); @@ -34,4 +35,13 @@ function formatAs12HourClock(time) { const suffix = isPM ? "pm" : "am"; return `${String(displayHour).padStart(2, "0")}:${minute} ${suffix}`; -} \ No newline at end of file +} +console.assert( + formatAs12HourClock("23:00") === "11:00 pm", +); +console.assert( + formatAs12HourClock("00:00") === "12:00 am", +); +console.assert( + formatAs12HourClock("12:00") === "12:00 pm", +); \ No newline at end of file