From cfed76f32f6980ce4c40ff1fa431a1c243a5ceda Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:35:14 +0100 Subject: [PATCH 01/18] angles_type --- Sprint-3/1-key-implement/1-get-angle-type.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..ea69201b9 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -9,7 +9,12 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; - // read to the end, complete line 36, then pass your test here + 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"; + + } // we're going to use this helper function to make our assertions easier to read @@ -43,14 +48,20 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + // ====> write your test here, and then add a line to pass the test in the function above // 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(270); +assertEquals(reflex, "Reflex angle"); \ No newline at end of file From a826dd0b8db9268f1d180263b7cb34ad110f90b4 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:47:17 +0100 Subject: [PATCH 02/18] properf fraction --- Sprint-3/1-key-implement/2-is-proper-fraction.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..149a98007 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -40,6 +40,7 @@ assertEquals(improperFraction, false); // target output: true // 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); +assertEquals(negativeFraction, true); // ====> complete with your assertion // Equal Numerator and Denominator check: @@ -47,6 +48,7 @@ const negativeFraction = isProperFraction(-4, 7); // target output: false // 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); +assertEquals(equalFraction, false); // ====> complete with your assertion // Stretch: From eb45e19e1b1d9136e8a2a5666ffdf1b25d4a822f Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:47:36 +0100 Subject: [PATCH 03/18] card_values --- Sprint-3/1-key-implement/3-get-card-value.js | 43 ++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..afdf840fa 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -8,44 +8,55 @@ // 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) { - if (rank === "A") return 11; + const rankChar = card.slice(0, -1); // Remove the last character (suit) + const rankInt = parseInt(rankChar); // Try to convert rank to a number + + if (rankChar === "A") return 11; // Ace is worth 11 + else if (["K", "Q", "J"].includes(rankChar)) return 10; // Face cards worth 10 + else if (rankInt >= 2 && rankInt <= 10) return rankInt; // 2–10 cards + else throw new Error("Invalid card rank."); } + // You need to write assertions for your function to check it works in different cases // we're going to use this helper function to make our assertions easier to read // if the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { - console.assert( - actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` - ); -} -// Acceptance criteria: - -// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), -// When the function getCardValue is called with this card string as input, -// Then it should return the numerical card value -const aceofSpades = getCardValue("A♠"); -assertEquals(aceofSpades, 11); + @@ -30,22 +38,38 @@ assertEquals(aceofSpades, 11); // Handle Number Cards (2-10): // Given a card with a rank between "2" and "9", -// When the function is called with such a card, +// When the function is called +// with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); +assertEquals(fiveofHearts, 5) +const sixofHearts = getCardValue("6♥"); +assertEquals(sixofHearts, 6) + // ====> write your test here, and then add a line to pass the test in the function above // 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 facecards = getCardValue("Q♥") +assertEquals(facecards, 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." +function assertThrowsInvalidCard(fn) { + try { + fn(); + console.assert(false, "Expected error for invalid card rank"); + } catch (error) { + assertEquals(error.message, "Invalid card rank."); + } +} \ No newline at end of file From 91d4ae387044df4667bb8cf7c53fae40db0457cf Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:51:28 +0100 Subject: [PATCH 04/18] angles_type --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..51a432791 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -2,6 +2,11 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; // replace with your completed function from key-implement + 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"; + throw new Error("Invalid angle"); } From 2d45e411239d4ed9e8a16142b355854f885a9b53 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:55:00 +0100 Subject: [PATCH 05/18] angle_type_test --- .../2-mandatory-rewrite/1-get-angle-type.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..2e6907d7d 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -10,15 +10,28 @@ 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(135)).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(270)).toEqual("Reflex angle"); +}); \ No newline at end of file From e068087364714428308904eeafe7a12a24b6042e Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 16:57:41 +0100 Subject: [PATCH 06/18] proper_fraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..b200e7c6b 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,6 @@ function isProperFraction(numerator, denominator) { - if (numerator < denominator) return true; - // add your completed function from key-implement here -} + if (denominator === 0) throw new Error("Denominator cannot be zero"); + return Math.abs(numerator) < Math.abs(denominator); +} module.exports = isProperFraction; \ No newline at end of file From ee60e26abaddd2d254e4be709987a74c8a26fc92 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:00:04 +0100 Subject: [PATCH 07/18] proper_fraction_test --- .../2-mandatory-rewrite/2-is-proper-fraction.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..5095a9090 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -5,7 +5,18 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for a proper fraction", () => { + expect(isProperFraction(5, 3)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return true for a negative fraction", () => { + expect(isProperFraction(-4, -6)).toEqual(true); +}); + + // Case 4: Identify Equal Numerator and Denominator: +test("should return false for a equal fraction", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); From 4ed95d23e6b4f43aa69082363ba27022bf9582b0 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:03:31 +0100 Subject: [PATCH 08/18] get_card_alue --- Sprint-3/2-mandatory-rewrite/3-get-card-value.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..5a31ab732 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,11 @@ function getCardValue(card) { - // replace with your code from key-implement - return 11; -} + const rankChar = card.slice(0, -1); + const rankInt = parseInt(rankChar); + + if (rankChar === "A") return 11; + if (["K", "Q", "J", "10"].includes(rankChar)) return 10;// If rank is 'K', 'Q', or 'J' (King, Queen, Jack), return 10 points + if (rankInt >= 2 && rankInt <= 9 && rankChar === rankInt.toString()) return rankInt; + + throw new Error("Invalid card rank."); +} module.exports = getCardValue; \ No newline at end of file From bab1b655b6a7550e2c95d38194941d8cb954a5b6 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:06:00 +0100 Subject: [PATCH 09/18] card_value_test --- .../3-get-card-value.test.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..00b652a9e 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -5,7 +5,27 @@ test("should return 11 for Ace of Spades", () => { expect(aceofSpades).toEqual(11); }); -// Case 2: Handle Number Cards (2-10): +// Case 2: Handle Number Cards (2-10) +test("should return 5 for 5 of Hearts", () => { + expect(getCardValue("5♥")).toEqual(5); +}); // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for Jack of Diamonds", () => { + 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 Clubs", () => { + expect(getCardValue("A♣")).toEqual(11); +}); // Case 5: Handle Invalid Cards: +test("should throw an error for empty string", () => { + expect(() => getCardValue("")).toThrow("Invalid card rank."); +}); \ No newline at end of file From f897a4fce87884591367244c3115639284177b10 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:08:54 +0100 Subject: [PATCH 10/18] count_js --- Sprint-3/3-mandatory-practice/implement/count.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..3b3e6d2b4 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } + } + return count; } -module.exports = countChar; \ No newline at end of file +module.exports = countChar; From c5a1bf33db0481eecd8424be3df99f86d2bedb69 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:11:23 +0100 Subject: [PATCH 11/18] count_test --- Sprint-3/3-mandatory-practice/implement/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..93a8a9e2a 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. +test("should return 0 when character does not exist in string", () => { + const str = "hello world"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From a5f5f0dc274c1062a895e759719c378a5f4bd411 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:13:36 +0100 Subject: [PATCH 12/18] get_ordinal --- .../implement/get-ordinal-number.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..9377a58fe 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,16 @@ function getOrdinalNumber(num) { - return "1st"; + const remainder10 = num % 10; + const remainder100 = num % 100; + + if (remainder100 >= 11 && remainder100 <= 13) { //deals with numbers 11,12,13 + return `${num}th`; //using template literal to combine num with a string th. + } + + if (remainder10 === 1) return `${num}st`; + if (remainder10 === 2) return `${num}nd`; + if (remainder10 === 3) return `${num}rd`; + + return `${num}th`; } module.exports = getOrdinalNumber; \ No newline at end of file From 8f74dd29b1bd824987597eb5c3b88656fa1829b1 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:19:54 +0100 Subject: [PATCH 13/18] ordinal_number_test --- .../implement/get-ordinal-number.test.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..165f89191 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -8,6 +8,30 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" -test("should return '1st' for 1", () => { - expect(getOrdinalNumber(1)).toEqual("1st"); - }); +test("append 'st' to numbers ending in 1, except those ending in 11", () => { + expect(getOrdinalNumber(1)).toEqual("1st"); + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(11)).toEqual("11th"); // exception case +}); + +test("append 'nd' to numbers ending in 2, except those ending in 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(12)).toEqual("12th"); // exception case +}); + +test("append 'rd' to numbers ending in 3, except those ending in 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(203)).toEqual("203rd"); + expect(getOrdinalNumber(13)).toEqual("13th"); // exception case +}); + +test("append 'th' to all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(28)).toEqual("28th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); \ No newline at end of file From 5e6e9779734df48622b664873d9bd3a69e48696b Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:22:06 +0100 Subject: [PATCH 14/18] repeated --- Sprint-3/3-mandatory-practice/implement/repeat.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..ebf6fe373 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,7 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if (count < 0) { + throw new Error("Invalid input: count must be non-negative"); + } + return String(str).repeat(count); } - module.exports = repeat; \ No newline at end of file From f6eeca9d8b75a3010d68e1028ea4ecbfe41501c9 Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:25:56 +0100 Subject: [PATCH 15/18] repeated_test --- .../implement/repeat.test.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..bc19fcf39 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -20,13 +20,28 @@ test("should repeat the string count times", () => { // Given a target string str and a count equal to 1, // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. - +test("should return original string when count is 1", () => { + const str = "hi"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hi"); +}); // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. - +test("should return empty string when count is 0", () => { + const str = "bye"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. +test("should throw an error when count is negative", () => { + const str = "oops"; + const count = -2; + expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer."); +}); From 39c451eb9f315639db9644b59cbf921b6f15c15f Mon Sep 17 00:00:00 2001 From: roja alagurajan Date: Mon, 7 Jul 2025 17:28:05 +0100 Subject: [PATCH 16/18] sprint3 --- Sprint-1/1-key-exercises/1-count.js | 6 --- Sprint-1/1-key-exercises/2-initials.js | 11 ----- Sprint-1/1-key-exercises/3-paths.js | 23 ----------- Sprint-1/1-key-exercises/4-random.js | 9 ---- Sprint-1/2-mandatory-errors/0.js | 2 - Sprint-1/2-mandatory-errors/1.js | 4 -- Sprint-1/2-mandatory-errors/2.js | 5 --- Sprint-1/2-mandatory-errors/3.js | 9 ---- Sprint-1/2-mandatory-errors/4.js | 2 - .../1-percentage-change.js | 22 ---------- .../3-mandatory-interpret/2-time-format.js | 25 ----------- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 27 ------------ Sprint-1/4-stretch-explore/chrome.md | 18 -------- Sprint-1/4-stretch-explore/objects.md | 16 -------- Sprint-1/readme.md | 35 ---------------- Sprint-2/1-key-errors/0.js | 13 ------ Sprint-2/1-key-errors/1.js | 20 --------- Sprint-2/1-key-errors/2.js | 20 --------- Sprint-2/2-mandatory-debug/0.js | 14 ------- Sprint-2/2-mandatory-debug/1.js | 13 ------ Sprint-2/2-mandatory-debug/2.js | 24 ----------- Sprint-2/3-mandatory-implement/1-bmi.js | 19 --------- Sprint-2/3-mandatory-implement/2-cases.js | 16 -------- Sprint-2/3-mandatory-implement/3-to-pounds.js | 6 --- Sprint-2/4-mandatory-interpret/time-format.js | 34 --------------- Sprint-2/5-stretch-extend/format-time.js | 25 ----------- Sprint-2/readme.md | 41 ------------------- 27 files changed, 459 deletions(-) delete mode 100644 Sprint-1/1-key-exercises/1-count.js delete mode 100644 Sprint-1/1-key-exercises/2-initials.js delete mode 100644 Sprint-1/1-key-exercises/3-paths.js delete mode 100644 Sprint-1/1-key-exercises/4-random.js delete mode 100644 Sprint-1/2-mandatory-errors/0.js delete mode 100644 Sprint-1/2-mandatory-errors/1.js delete mode 100644 Sprint-1/2-mandatory-errors/2.js delete mode 100644 Sprint-1/2-mandatory-errors/3.js delete mode 100644 Sprint-1/2-mandatory-errors/4.js delete mode 100644 Sprint-1/3-mandatory-interpret/1-percentage-change.js delete mode 100644 Sprint-1/3-mandatory-interpret/2-time-format.js delete mode 100644 Sprint-1/3-mandatory-interpret/3-to-pounds.js delete mode 100644 Sprint-1/4-stretch-explore/chrome.md delete mode 100644 Sprint-1/4-stretch-explore/objects.md delete mode 100644 Sprint-1/readme.md delete mode 100644 Sprint-2/1-key-errors/0.js delete mode 100644 Sprint-2/1-key-errors/1.js delete mode 100644 Sprint-2/1-key-errors/2.js delete mode 100644 Sprint-2/2-mandatory-debug/0.js delete mode 100644 Sprint-2/2-mandatory-debug/1.js delete mode 100644 Sprint-2/2-mandatory-debug/2.js delete mode 100644 Sprint-2/3-mandatory-implement/1-bmi.js delete mode 100644 Sprint-2/3-mandatory-implement/2-cases.js delete mode 100644 Sprint-2/3-mandatory-implement/3-to-pounds.js delete mode 100644 Sprint-2/4-mandatory-interpret/time-format.js delete mode 100644 Sprint-2/5-stretch-extend/format-time.js delete mode 100644 Sprint-2/readme.md diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index 117bcb2b6..000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,6 +0,0 @@ -let count = 0; - -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 diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js deleted file mode 100644 index 47561f617..000000000 --- a/Sprint-1/1-key-exercises/2-initials.js +++ /dev/null @@ -1,11 +0,0 @@ -let firstName = "Creola"; -let middleName = "Katherine"; -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 = ``; - -// 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 deleted file mode 100644 index ab90ebb28..000000000 --- a/Sprint-1/1-key-exercises/3-paths.js +++ /dev/null @@ -1,23 +0,0 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -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 = ; - -// 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 deleted file mode 100644 index 292f83aab..000000000 --- a/Sprint-1/1-key-exercises/4-random.js +++ /dev/null @@ -1,9 +0,0 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// In this exercise, you will need to work out what num represents? -// 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 diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js deleted file mode 100644 index cf6c5039f..000000000 --- a/Sprint-1/2-mandatory-errors/0.js +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 7a43cbea7..000000000 --- a/Sprint-1/2-mandatory-errors/1.js +++ /dev/null @@ -1,4 +0,0 @@ -// trying to create an age variable and then reassign the value by 1 - -const age = 33; -age = age + 1; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js deleted file mode 100644 index e09b89831..000000000 --- a/Sprint-1/2-mandatory-errors/2.js +++ /dev/null @@ -1,5 +0,0 @@ -// 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"; diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js deleted file mode 100644 index ec101884d..000000000 --- a/Sprint-1/2-mandatory-errors/3.js +++ /dev/null @@ -1,9 +0,0 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); - -// The last4Digits variable should store the last 4 digits of cardNumber -// However, the code isn't working -// Before running the code, make and explain a prediction about why the code won't work -// 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 diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js deleted file mode 100644 index 21dad8c5d..000000000 --- a/Sprint-1/2-mandatory-errors/4.js +++ /dev/null @@ -1,2 +0,0 @@ -const 12HourClockTime = "20:53"; -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 deleted file mode 100644 index e24ecb8e1..000000000 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ /dev/null @@ -1,22 +0,0 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -console.log(`The percentage change is ${percentageChange}`); - -// Read the code and then answer the questions below - -// a) How many function calls are there in this file? Write down all the lines where a function call is made - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// d) Identify all the lines that are variable declarations - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js deleted file mode 100644 index 47d239558..000000000 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ /dev/null @@ -1,25 +0,0 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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? - -// b) How many function calls are there? - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -// e) What do you think the variable result represents? Can you think of a better name for this variable? - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index 60c9ace69..000000000 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,27 +0,0 @@ -const penceString = "399p"; - -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"); - -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md deleted file mode 100644 index e7dd5feaf..000000000 --- a/Sprint-1/4-stretch-explore/chrome.md +++ /dev/null @@ -1,18 +0,0 @@ -Open a new window in Chrome, - -then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -Let's try an example. - -In the Chrome console, -invoke the function `alert` with an input string of `"Hello world!"`; - -What effect does calling the `alert` function have? - -Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. - -What effect does calling the `prompt` function have? -What is the return value of `prompt`? diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md deleted file mode 100644 index 0216dee56..000000000 --- a/Sprint-1/4-stretch-explore/objects.md +++ /dev/null @@ -1,16 +0,0 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -Open the Chrome devtools Console, type in `console.log` and then hit enter - -What output do you get? - -Now enter just `console` in the Console, what output do you get back? - -Try also entering `typeof console` - -Answer the following questions: - -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? diff --git a/Sprint-1/readme.md b/Sprint-1/readme.md deleted file mode 100644 index 62d24c958..000000000 --- a/Sprint-1/readme.md +++ /dev/null @@ -1,35 +0,0 @@ -# 🧭 Guide to Week 1 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/1/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you _how_ to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -This README will guide you through the different sections for this week. - -## 1 Exercises - -In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 2 Errors - -In this section, you'll need to go to each file in `errors` directory and run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. - -## 3 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar - learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -https://developer.mozilla.org/en-US/docs/Web/JavaScript - -## 4 Explore - Stretch 💪 - -This stretch activity will get you to start exploring new concepts and environments by yourself. It will do so by prompting you to reflect on some questions. diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js deleted file mode 100644 index 653d6f5a0..000000000 --- a/Sprint-2/1-key-errors/0.js +++ /dev/null @@ -1,13 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -// 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; -} - -// =============> write your explanation here -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js deleted file mode 100644 index f2d56151f..000000000 --- a/Sprint-2/1-key-errors/1.js +++ /dev/null @@ -1,20 +0,0 @@ -// Predict and explain first... - -// Why will an error occur when this program runs? -// =============> write your prediction here - -// 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 - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js deleted file mode 100644 index aad57f7cf..000000000 --- a/Sprint-2/1-key-errors/2.js +++ /dev/null @@ -1,20 +0,0 @@ - -// 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 - -function square(3) { - return num * num; -} - -// =============> write the error message here - -// =============> explain this error message here - -// Finally, correct the code to fix the problem - -// =============> write your new code here - - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js deleted file mode 100644 index b27511b41..000000000 --- a/Sprint-2/2-mandatory-debug/0.js +++ /dev/null @@ -1,14 +0,0 @@ -// Predict and explain first... - -// =============> write your prediction here - -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 - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js deleted file mode 100644 index 37cedfbcf..000000000 --- a/Sprint-2/2-mandatory-debug/1.js +++ /dev/null @@ -1,13 +0,0 @@ -// Predict and explain first... -// =============> write your prediction here - -function sum(a, b) { - return; - a + b; -} - -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js deleted file mode 100644 index 57d3f5dc3..000000000 --- a/Sprint-2/2-mandatory-debug/2.js +++ /dev/null @@ -1,24 +0,0 @@ -// Predict and explain first... - -// Predict the output of the following code: -// =============> Write your prediction here - -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 -// =============> write the output here -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - -// 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-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js deleted file mode 100644 index 17b1cbde1..000000000 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ /dev/null @@ -1,19 +0,0 @@ -// 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 their Body Mass Index to 1 decimal place - -function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js deleted file mode 100644 index 5b0ef77ad..000000000 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ /dev/null @@ -1,16 +0,0 @@ -// 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 diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js deleted file mode 100644 index 6265a1a70..000000000 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ /dev/null @@ -1,6 +0,0 @@ -// In Sprint-1, there is a program written in interpret/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 diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js deleted file mode 100644 index 7c98eb0e8..000000000 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ /dev/null @@ -1,34 +0,0 @@ -function pad(num) { - return num.toString().padStart(2, "0"); -} - -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)}`; -} - -// 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 - -// 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 - -// c) What is the return value of pad is called for the first time? -// =============> write your answer here - -// 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 - -// 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 diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js deleted file mode 100644 index 32a32e66b..000000000 --- a/Sprint-2/5-stretch-extend/format-time.js +++ /dev/null @@ -1,25 +0,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 hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; -} - -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); diff --git a/Sprint-2/readme.md b/Sprint-2/readme.md deleted file mode 100644 index 44c118e33..000000000 --- a/Sprint-2/readme.md +++ /dev/null @@ -1,41 +0,0 @@ -# 🧭 Guide to week 2 exercises - -> https://programming.codeyourfuture.io/structuring-data/sprints/2/prep/ - -> [!TIP] -> You should always do the prep work _before_ attempting the coursework. -> The prep shows you how to do the coursework. -> There is often a step by step video you can code along with too. -> Do the prep. - -## 1 Errors - -In this section, you need to go to each file in `errors` directory. Read the file and predict what error will happen. Then run the file with node to check what the error is. Your task is to interpret the error message and explain why it occurs. The [errors documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors) will help you figure out the solution. - -## 2 Debug - -In this section, you need to go to each file in `debug` to **explain and predict** why the program isn't behaving as intended. Then you'll need to run the program with node to check your prediction. You will also need to correct the code too. - -## 3 Implement - -In this section, you will have a short set of requirements about a function. You will need to implement a function based off this set of requirements. Make sure you check your function works for a number of different inputs. - -Here is a recommended order: - -1. `1-bmi.js` -1. `2-cases.js` -1. `3-to-pounds.js` - -## 4 Interpret - -In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar. - -You must use documentation to make sense of anything unfamiliar. Learning how to look things up this way is a fundamental part of being a developer! - -You can also use `console.log` to check the value of different variables in the code. - -## 5 Extend - -In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times. - -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. This section is not mandatory, but it will also help you solve some similar kata in Codewars. From 42685fd0cf2444456463e2e731d070d105931c1d Mon Sep 17 00:00:00 2001 From: Roja Date: Thu, 17 Jul 2025 19:20:45 +0100 Subject: [PATCH 17/18] Update 1-get-angle-type.js --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index 51a432791..52766c162 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,4 +1,5 @@ function getAngleType(angle) { + if (angle <= 0 || angle >= 360) return "Invalid angle"; if (angle === 90) return "Right angle"; // replace with your completed function from key-implement @@ -20,4 +21,4 @@ function getAngleType(angle) { // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now // we have just written the CommonJS module.exports syntax for you -module.exports = getAngleType; \ No newline at end of file +module.exports = getAngleType; From bf9ed49894cb2e64880760635d587dfe401ce27b Mon Sep 17 00:00:00 2001 From: Roja Date: Thu, 17 Jul 2025 22:46:29 +0100 Subject: [PATCH 18/18] Update 3-get-card-value.js --- Sprint-3/2-mandatory-rewrite/3-get-card-value.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 5a31ab732..93d133ced 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,11 +1,13 @@ function getCardValue(card) { const rankChar = card.slice(0, -1); - const rankInt = parseInt(rankChar); + if (rankChar === "A") return 11; if (["K", "Q", "J", "10"].includes(rankChar)) return 10;// If rank is 'K', 'Q', or 'J' (King, Queen, Jack), return 10 points - if (rankInt >= 2 && rankInt <= 9 && rankChar === rankInt.toString()) return rankInt; + + const validRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + if (validRanks.includes(rankChar)) return Number(rankChar); // Define all valid numeric ranks as strings throw new Error("Invalid card rank."); } -module.exports = getCardValue; \ No newline at end of file +module.exports = getCardValue;