From 53f918858da8aa6bd98ced053e9715578f987b82 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Sat, 11 Oct 2025 22:14:19 +0100 Subject: [PATCH 1/7] new work space in vscode --- Sprint-1/1-key-exercises/1-count.js | 4 ++++ Sprint-1/1-key-exercises/2-initials.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..a5f73d281 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,7 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +Answer +// Line 3; when we the right side first count in the right side is considerd as 0 so 0+1 will be 1. +// But the = sign does not mean the mathimatical equal, its function is to take the result on the right and store it on the left. +// Therfore if we write the same code in next line the result is not one but 2 \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..4a09edec5 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; // https://www.google.com/search?q=get+first+character+of+string+mdn From a825bf7a5a914d02b03fe59a2c255781d0c75cd4 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Mon, 13 Oct 2025 07:49:27 +0100 Subject: [PATCH 2/7] correctin and updating the exercise --- Sprint-1/1-key-exercises/1-count.js | 6 +++--- Sprint-1/1-key-exercises/3-paths.js | 6 ++++-- Sprint-1/1-key-exercises/4-random.js | 19 +++++++++++++++++++ Sprint-1/2-mandatory-errors/0.js | 4 ++-- Sprint-1/2-mandatory-errors/1.js | 3 ++- Sprint-1/2-mandatory-errors/2.js | 3 ++- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index a5f73d281..684b66fcb 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -5,6 +5,6 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing Answer -// Line 3; when we the right side first count in the right side is considerd as 0 so 0+1 will be 1. -// But the = sign does not mean the mathimatical equal, its function is to take the result on the right and store it on the left. -// Therfore if we write the same code in next line the result is not one but 2 \ No newline at end of file +// Line 3; when we the right side first count in the right side is considered as 0 so 0+1 will be 1. +// But the = sign does not mean the mathematical equal, its function is to take the result on the right and store it on the left. +// Therefore if we write the same code in next line the result is not one but 2 \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..cbe18ba20 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,9 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const lastDotIndex = base.lastIndexOf("."); +const ext = base.slice(lastDotIndex + 1); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..526f7c468 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,22 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +// Answer + +// 1. +// The num in this scenario represent any integer between 1 and 100 + +// 2. +// Math.floor: rounds the number down to the nearest whole number which means it ignores the number to the right of the point. eg. 4.7=4 +// Math.random is a js code that returns any random number that is greater than or equal to 0 and less than 1 +//* is multiplication +// maximum is the maximum given number, in this case 100 +//- is a subtraction +// minimum is the minimum given number, in this case 1 +//(maximum - minimum +1) this is subtracting the minimum number from the maximum and add 1, in this case (100-1+1)=100 +//+ minimum: this turns the value by adding 1 to the whole equation. + +//3. + +console.log(num) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..65ad3030d 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..c3714c46a 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..ae2731079 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From d873260b5e5316c20cc0360089ef83bc8f095770 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Wed, 15 Oct 2025 08:17:41 +0100 Subject: [PATCH 3/7] Answering each question with in the file by puting // to separate from the code --- Sprint-1/2-mandatory-errors/3.js | 10 +++++++ Sprint-1/2-mandatory-errors/4.js | 5 +++- .../1-percentage-change.js | 27 +++++++++++++++++++ .../3-mandatory-interpret/2-time-format.js | 7 +++++ Sprint-1/3-mandatory-interpret/3-to-pounds.js | 12 ++++++++- 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..54901d1d7 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,3 +7,13 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +//Answer + +// This code is not working because slice() is working with "string" or "arrays" but not with numbers. and cardNumber is a number. +// So the error is "TypeError:cardNumber.slice is not a function"\ +// slice() didn't recognize the number as I expected before. + +const cardNumber = 4533787178994213; +const last4Digits = String(cardNumber).slice(-4); +console.log(last4Digits) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..148952cbc 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; +// the 12 and 24 are changing position +const 24HourClockTime = "20:53"; +const 12hourClockTime = "08:53"; \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..4a1858990 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,10 +13,37 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made +// There are five functions calls. +//carPrice.replaceAll(",", "") +//Number(carPrice.replaceAll(",", "")) +//priceAfterOneYear.replaceAll("," "") +//Number(priceAfterOneYear.replaceAll("," "")) +//console.log(`The percentage change is ${percentageChange}`) + // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +// When I run the code the error is "syntaxError: missing ) after argument list. +// The error comes from line 5 +// The error occurs due to the missing coma between the two strings in the replaceAll() call. +// Add coma between the two strings "priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));" + // c) Identify all the lines that are variable reassignment statements +// there are to lines that state variable reassignment +// carPrice = Number(carPrice.replaceAll(",", "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + // d) Identify all the lines that are variable declarations +// There are fore variable declarations (line 1, line 2, line 7, line 8) +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; +// const priceDifference = carPrice - priceAfterOneYear; +// const percentageChange = (priceDifference / carPrice) * 100; + + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// carprice at line 1 is a string in order to calculate for the next line of codes you have to change the string ti number. +// carPrice.replaceAll(",","")). delete the coma in between the number (e.g from "10,000" to "10000") +// number() change the string to number ("10000" to 10000) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..d2fa9711c 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,21 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +// There are 6 variable declaration. "line1, line3, line4, line6, line7, line9" // b) How many function calls are there? +// There is only one function call in this program "console.log(result);" // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is called remainder. There fore movieLength % 60 represents the remainder of the movie length after dividing by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// totalMinutes are calculated by subtracting the remaining seconds from movie length and divided by 60 to get full minutes. this helps to get a number which divided by 60 with out reminder. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// result represents the total length of the movie in the form of Hour: minute: second +// moveDurationFormatted can be a better name to replace result. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Yes it works for all value. the only thing that is concerning is the validation of movieLength as the negative integer also gives value which is unrealistic. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..7934f9a8e 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399p"; +onst penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -25,3 +25,13 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); +// This remove the p and left the string with only 399 +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// this code make sure that the string has 3 character. since one pound is equal 100 pence. +// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); +// This code takes the number leaving the last 2 digits "in this case it takes 3 and leave 99" +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); +// This code takes the last digit from the string and also make sure that it has only two digits this gives a "99" value. +// 6. console.log(`£${pounds}.${pence}`); +// his gives a result with £ sign and separated by . " in this case it gives £3.99 " From bf0a9bf42d091c6e104c6c5e43fd9b1d12a94277 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Sat, 25 Oct 2025 08:03:25 +0100 Subject: [PATCH 4/7] testing the code using assert --- .../implement/1-get-angle-type.js | 20 ++++++++++-- .../implement/2-is-proper-fraction.js | 27 ++++++++++++++++ .../implement/3-get-card-value.js | 31 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index ca1dfe7f2..adb7015e1 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -10,6 +10,18 @@ function getAngleType(angle) { if (angle === 90) { return "Right angle"; + } + if (angle < 90) { + return "Acute angle"; + } + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } + if (angle > 180 && angle < 360) { + return "Reflex angle"; } // Run the tests, work out what Case 2 is testing, and implement the required code here. // Then keep going for the other cases, one at a time. @@ -51,13 +63,17 @@ assertEquals(acute, "Acute angle"); // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); // ====> write your test here, and then add a line to pass the test in the function above - +assertEquals(obtuse, "Obtuse angle"); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" // ====> write your test here, and then add a line to pass the test in the function above +const Straight = getAngleType(180); +assertEquals(Straight, "Straight angle"); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +// ====> write your test here, and then add a line to pass the test in the function above +const reflex = getAngleType(220); +assertEquals(reflex, "Reflex angle"); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index a4739af77..fffff728e 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,6 +11,18 @@ function isProperFraction(numerator, denominator) { if (numerator < denominator) { return true; } + if (numerator > denominator) { + return false; + } + if (numerator === denominator) { + return true; + } + if (numerator === 0) { + return true; + } + if (denominator===0) { + return true; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -47,6 +59,7 @@ assertEquals(improperFraction, false); // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); // ====> complete with your assertion +assertEquals(negativeFraction, true); // Equal Numerator and Denominator check: // Input: numerator = 3, denominator = 3 @@ -54,6 +67,20 @@ const negativeFraction = isProperFraction(-4, 7); // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); // ====> complete with your assertion +assertEquals(equalFraction, true); // Stretch: // What other scenarios could you test for? +// zero value check: +// Input: numerator = 0, denominator = 5 +// target output: true +// Explanation: The fraction 0/5 will be zero because zero divided any number will give zero. The function should return true. +const zeroValue = isProperFraction(0, 5); +assertEquals(zeroValue, true); + +// undefine value check: +// Input: numerator = 5, denominator = 0 +// target output: true +// Explanation: The fraction 5/0 will be undefine because any number divided by zero will be undefine. The function should return true. +const undefine = isProperFraction(0, 5); +assertEquals(undefine, true); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 266525d1b..f346da933 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -8,9 +8,19 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { + const rank = card.slice(0, -1); if (rank === "A") { return 11; } + if (["K", "Q", "J"].includes(rank)) { + return 10; + } + + const num = parseInt(rank, 10); + if (num >= 2 && num <= 10) { + return num; + } + throw new Error("Invalid card rank."); } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,18 +50,39 @@ assertEquals(aceofSpades, 11); // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); // ====> write your test here, and then add a line to pass the test in the function above +assertEquals(fiveofHearts, 5); // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const jack = getCardValue("J♦"); +assertEquals(jack, 10); + +const queen = getCardValue("Q♣"); +assertEquals(queen, 10); + +const king = getCardValue("K♠"); +assertEquals(king, 10); + +const ten = getCardValue("10♥"); +assertEquals(ten, 10); // Handle Ace (A): // Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. +const Ace = getCardValue("A♦"); +assertEquals(Ace, 11); // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." +try { + getCardValue("B"); + console.error("Test failed: Expected error for invalid card rank."); +} catch (e) { + assertEquals(e.message, "Invalid card rank."); +} + From 958730d0419d99b6e35028e4224092d77611ee00 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Sat, 25 Oct 2025 08:05:54 +0100 Subject: [PATCH 5/7] testing code using jest --- .../1-get-angle-type.test.js | 12 ++++++++ .../2-is-proper-fraction.test.js | 9 ++++++ .../3-get-card-value.test.js | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index 4a92a3e82..34557ba5a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -12,15 +12,27 @@ test("should identify right angle (90°)", () => { // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" +test("should identify acute angle (< 90°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); +}); // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify obtuse angle (> 90° and < 180°)", () => { + expect(getAngleType(120)).toEqual("Obtuse angle"); +}); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" +test("should identify reflex angle (> 180° and < 360°)", () => { + expect(getAngleType(220)).toEqual("Reflex angle"); +}); \ No newline at end of file diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index caf08d15b..98ff5d073 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return folse for a improper fraction", () => { + expect(isProperFraction(5, 2)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return true for a negative fraction", () => { + expect(isProperFraction(-4, 7)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return true for a equal fraction", () => { + expect(isProperFraction(3, 3)).toEqual(true); +}); diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index 04418ff72..9da58d47b 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -8,6 +8,35 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): +test("should return 3 for 3 of Clubs", () => { + expect(getCardValue("3♣")).toEqual(3); +}); + +test("should return 7 for 7 of Spades", () => { + expect(getCardValue("7♠")).toEqual(7); +}); + +test("should return 9 for 9 of Diamonds", () => { + expect(getCardValue("9♦")).toEqual(9); +}); + // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for Jack of Clubs", () => { + expect(getCardValue("J♦")).toEqual(10); +}); + +test("should return 10 for Queen of Spades", () => { + expect(getCardValue("Q♣")).toEqual(10); +}); + +test("should return 10 for King of Hearts", () => { + expect(getCardValue("K♠")).toEqual(10); +}); // Case 4: Handle Ace (A): +test("should return 11 for Ace of Diamonds", () => { + expect(getCardValue("A♦")).toEqual(11); +}); // Case 5: Handle Invalid Cards: +test("should return null for invalid card 'B'", () => { + expect(getCardValue("Z♠")).toBeNull(); +}); \ No newline at end of file From 99f9720c29ede190336f1e4e901bb03d35ae70b2 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Mon, 27 Oct 2025 07:32:12 +0000 Subject: [PATCH 6/7] restoring sprint 1 folder from cyf main --- Sprint-1/1-key-exercises/1-count.js | 4 --- Sprint-1/1-key-exercises/2-initials.js | 2 +- Sprint-1/1-key-exercises/3-paths.js | 6 ++--- Sprint-1/1-key-exercises/4-random.js | 19 ------------- Sprint-1/2-mandatory-errors/0.js | 4 +-- Sprint-1/2-mandatory-errors/1.js | 3 +-- Sprint-1/2-mandatory-errors/2.js | 3 +-- Sprint-1/2-mandatory-errors/3.js | 10 ------- Sprint-1/2-mandatory-errors/4.js | 5 +--- .../1-percentage-change.js | 27 ------------------- .../3-mandatory-interpret/2-time-format.js | 7 ----- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 12 +-------- 12 files changed, 9 insertions(+), 93 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 684b66fcb..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,7 +4,3 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing -Answer -// Line 3; when we the right side first count in the right side is considered as 0 so 0+1 will be 1. -// But the = sign does not mean the mathematical equal, its function is to take the result on the right and store it on the left. -// Therefore if we write the same code in next line the result is not one but 2 \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 4a09edec5..47561f617 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; +let initials = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index cbe18ba20..ab90ebb28 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,9 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = filePath.slice(0, lastSlashIndex); -const lastDotIndex = base.lastIndexOf("."); -const ext = base.slice(lastDotIndex + 1); - +const dir = ; +const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 526f7c468..292f83aab 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,22 +7,3 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing - -// Answer - -// 1. -// The num in this scenario represent any integer between 1 and 100 - -// 2. -// Math.floor: rounds the number down to the nearest whole number which means it ignores the number to the right of the point. eg. 4.7=4 -// Math.random is a js code that returns any random number that is greater than or equal to 0 and less than 1 -//* is multiplication -// maximum is the maximum given number, in this case 100 -//- is a subtraction -// minimum is the minimum given number, in this case 1 -//(maximum - minimum +1) this is subtracting the minimum number from the maximum and add 1, in this case (100-1+1)=100 -//+ minimum: this turns the value by adding 1 to the whole equation. - -//3. - -console.log(num) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index 65ad3030d..cf6c5039f 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -//This is just an instruction for the first activity - but it is just for human consumption -//We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +This is just an instruction for the first activity - but it is just for human consumption +We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index c3714c46a..7a43cbea7 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,5 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -let age = 33; +const age = 33; age = age + 1; -console.log(age) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index ae2731079..e09b89831 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,6 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? - -const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); +const cityOfBirth = "Bolton"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index 54901d1d7..ec101884d 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,13 +7,3 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value - -//Answer - -// This code is not working because slice() is working with "string" or "arrays" but not with numbers. and cardNumber is a number. -// So the error is "TypeError:cardNumber.slice is not a function"\ -// slice() didn't recognize the number as I expected before. - -const cardNumber = 4533787178994213; -const last4Digits = String(cardNumber).slice(-4); -console.log(last4Digits) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 148952cbc..21dad8c5d 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,5 +1,2 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; -// the 12 and 24 are changing position -const 24HourClockTime = "20:53"; -const 12hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; \ No newline at end of file diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 4a1858990..e24ecb8e1 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,37 +13,10 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made -// There are five functions calls. -//carPrice.replaceAll(",", "") -//Number(carPrice.replaceAll(",", "")) -//priceAfterOneYear.replaceAll("," "") -//Number(priceAfterOneYear.replaceAll("," "")) -//console.log(`The percentage change is ${percentageChange}`) - // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? -// When I run the code the error is "syntaxError: missing ) after argument list. -// The error comes from line 5 -// The error occurs due to the missing coma between the two strings in the replaceAll() call. -// Add coma between the two strings "priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));" - // c) Identify all the lines that are variable reassignment statements -// there are to lines that state variable reassignment -// carPrice = Number(carPrice.replaceAll(",", "")); -// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - // d) Identify all the lines that are variable declarations -// There are fore variable declarations (line 1, line 2, line 7, line 8) -// let carPrice = "10,000"; -// let priceAfterOneYear = "8,543"; -// const priceDifference = carPrice - priceAfterOneYear; -// const percentageChange = (priceDifference / carPrice) * 100; - - // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? - -// carprice at line 1 is a string in order to calculate for the next line of codes you have to change the string ti number. -// carPrice.replaceAll(",","")). delete the coma in between the number (e.g from "10,000" to "10000") -// number() change the string to number ("10000" to 10000) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index d2fa9711c..47d239558 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,21 +12,14 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? -// There are 6 variable declaration. "line1, line3, line4, line6, line7, line9" // b) How many function calls are there? -// There is only one function call in this program "console.log(result);" // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// % is called remainder. There fore movieLength % 60 represents the remainder of the movie length after dividing by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// totalMinutes are calculated by subtracting the remaining seconds from movie length and divided by 60 to get full minutes. this helps to get a number which divided by 60 with out reminder. // e) What do you think the variable result represents? Can you think of a better name for this variable? -// result represents the total length of the movie in the form of Hour: minute: second -// moveDurationFormatted can be a better name to replace result. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// Yes it works for all value. the only thing that is concerning is the validation of movieLength as the negative integer also gives value which is unrealistic. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 7934f9a8e..60c9ace69 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -onst penceString = "399p"; +const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -25,13 +25,3 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" -// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); -// This remove the p and left the string with only 399 -// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -// this code make sure that the string has 3 character. since one pound is equal 100 pence. -// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2); -// This code takes the number leaving the last 2 digits "in this case it takes 3 and leave 99" -// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); -// This code takes the last digit from the string and also make sure that it has only two digits this gives a "99" value. -// 6. console.log(`£${pounds}.${pence}`); -// his gives a result with £ sign and separated by . " in this case it gives £3.99 " From e5af9d8ab59fa46dd7b8c360b96650a4e188a0b1 Mon Sep 17 00:00:00 2001 From: Abrsh100 Date: Tue, 28 Oct 2025 08:38:04 +0000 Subject: [PATCH 7/7] responding to the valuable comments --- .../implement/2-is-proper-fraction.js | 4 ++-- .../rewrite-tests-with-jest/3-get-card-value.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index fffff728e..fb7756654 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,7 +15,7 @@ function isProperFraction(numerator, denominator) { return false; } if (numerator === denominator) { - return true; + return false; } if (numerator === 0) { return true; @@ -67,7 +67,7 @@ assertEquals(negativeFraction, true); // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); // ====> complete with your assertion -assertEquals(equalFraction, true); +assertEquals(equalFraction, false); // Stretch: // What other scenarios could you test for? diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index 9da58d47b..979f29365 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -37,6 +37,6 @@ test("should return 11 for Ace of Diamonds", () => { expect(getCardValue("A♦")).toEqual(11); }); // Case 5: Handle Invalid Cards: -test("should return null for invalid card 'B'", () => { - expect(getCardValue("Z♠")).toBeNull(); -}); \ No newline at end of file +test("should throw an error for invalid card 'Z♠'", () => { + expect(() => getCardValue("Z♠")).toThrow("Invalid card"); +});