Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9d43b8b
npm installed
TzeMingHo Sep 18, 2025
150a780
In 1 key-errors, made a preditions, explained the syntax error, and f…
TzeMingHo Sep 18, 2025
8fdb210
In 1-key-errors, deleted unwanted variable, and console.log function …
TzeMingHo Sep 18, 2025
24f2d3c
In 1-key-errors/2.js, replacing 3 with num as parameter
TzeMingHo Sep 18, 2025
96ebf89
In 2-mandatory-debug/0.js, updated return in the function
TzeMingHo Sep 18, 2025
b2f87c5
In 2-mandatory-debug/1.js, updated return inline with a+b
TzeMingHo Sep 18, 2025
b73f73f
In 2-mandatory-debug/2.js, adding a parameter in the function
TzeMingHo Sep 18, 2025
72112ca
In 3-mandatory-implement/1-bmi.js, filled in the function to get bmi …
TzeMingHo Sep 18, 2025
a505558
In 3-mandatory-implement/2-cases.js, created a function to convert lo…
TzeMingHo Sep 18, 2025
6c1636f
In 3-mandatory-implement/3-to-pounds.js, created a reusable function …
TzeMingHo Sep 22, 2025
401db2b
In 4-mandatory-interpret/time-format.js, filled in answers
TzeMingHo Sep 22, 2025
5733d12
In 5-stretch-extend/format-time.js, tried edge cases and invalid inputs
TzeMingHo Sep 22, 2025
096632e
correcting padStart for minutes String
TzeMingHo Sep 22, 2025
b0fe035
Remove package-lock.json from pull request
TzeMingHo Sep 22, 2025
7a2b0a1
ignore package-lock.json
TzeMingHo Sep 22, 2025
096f9b6
adding 5 tests and passing 5 tests for 1-get-angle-type
TzeMingHo Sep 23, 2025
5245e20
finsihed 4 cases and tests of proper fraction, start doing stretch cases
TzeMingHo Sep 23, 2025
bc00dfc
adding 9 stretch tests in proper fraction
TzeMingHo Sep 23, 2025
bc1b331
adding tests for card values in blackjack
TzeMingHo Sep 23, 2025
51eedee
restore sprint-2 from origin/main
TzeMingHo Sep 23, 2025
6c04424
restore gitignore from origin/main
TzeMingHo Sep 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ function getAngleType(angle) {
if (angle === 90) {
return "Right 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.
// 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.
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";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -51,13 +63,18 @@ 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
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(250);
assertEquals(reflex, "Reflex angle");
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
}

Expand Down Expand Up @@ -47,13 +49,78 @@ 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
// 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);
// ====> complete with your assertion
assertEquals(equalFraction, false);

// Stretch:
// What other scenarios could you test for?

// Stretch 1: negative denominator
// Input: numerator = 2, denominator = -3
// target output: true
// Explanation: The fraction 2/-3 is a proper fraction because the absolute value of denominator (3) is larger than the numerator (2).
const negativeDenominator = isProperFraction(2, -3);
assertEquals(negativeDenominator, true);

// Stretch 2: zero numerator
// Input: numerator = 0, denominator = 5
// target output: true
// Explanation: The fraction 0/5 is a proper fraction because the absolute value of numerator (0) is less than the denominator (5).
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true);

// Stretch 3: zero denominator - this is mathematically undefined but we can decide how we want to handle it
// Input: numerator = 5, denominator = 0
// target output: false
// Explanation: The fraction 5/0 is undefined in mathematics. In this implementation, we choose to return false.
const zeroDenominator = isProperFraction(5, 0);
assertEquals(zeroDenominator, false);

// Stretch 4: both zero
// Input: numerator = 0, denominator = 0
// target output: false
// Explanation: The fraction 0/0 is indeterminate in mathematics. In this implementation, we choose to return false.
const bothZero = isProperFraction(0, 0);
assertEquals(bothZero, false);

// Stretch 5: negative numerator and denominator
// Input: numerator = -3, denominator = -5
// target output: true
// Explanation: The fraction -3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true.
const negativeNumeratorAndDenominator = isProperFraction(-3, -5);
assertEquals(negativeNumeratorAndDenominator, true);

// Stretch 6: improper negative numerator and denominator
// Input: numerator = -3, denominator = -2
// target output: false
// Explanation: The fraction -3/-2 is an improper fraction because the absolute value of the numerator (3) is greater than the absolute value of the denominator (2). The function should return false.
const properNegativeNumeratorAndDenominator = isProperFraction(-3, -2);
assertEquals(properNegativeNumeratorAndDenominator, false);

// Stretch 7: decimal values
// Input: numerator = 2.5, denominator = 3.5
// target output: true
// Explanation: The fraction 2.5/3.5 is a proper fraction because the absolute value of the numerator (2.5) is less than the absolute value of the denominator (3.5). The function should return true.
const decimalValues = isProperFraction(2.5, 3.5);
assertEquals(decimalValues, true);

// Stretch 8: improper decimal values
// Input: numerator = 3.5, denominator = 2.5
// target output: false
// Explanation: The fraction 3.5/2.5 is an improper fraction because the absolute value of the numerator (3.5) is greater than the absolute value of the denominator (2.5). The function should return false.
const improperDecimalValues = isProperFraction(3.5, 2.5);
assertEquals(improperDecimalValues, false);

// Stretch 9: invalid inputs (non-numeric values)
// Input: numerator = "a", denominator = 2
// target output: false
// Explanation: The function should handle non-numeric inputs gracefully. In this case, we choose to return false.
const invalidInputs = isProperFraction("a", 2);
assertEquals(invalidInputs, false);
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
// 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 (rank === "K" || rank === "Q" || rank === "J" || rank === "10") {
return 10;
}
const numericRank = Number(rank);
if (numericRank >= 2 && numericRank <= 9) {
return numericRank;
}
return "Error: Invalid card rank";
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -31,27 +40,44 @@ function assertEquals(actualOutput, targetOutput) {
// 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);
const aceOfSpades = getCardValue("A♠");
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,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
const nineOfHearts = getCardValue("9♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(nineOfHearts, 9);

// 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 kingOfDiamonds = getCardValue("K♦");
assertEquals(kingOfDiamonds, 10);
const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);
const jackOfHearts = getCardValue("J♥");
assertEquals(jackOfHearts, 10);
const tenOfSpades = getCardValue("10♠");
assertEquals(tenOfSpades, 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 aceOfHearts = getCardValue("A♥");
assertEquals(aceOfHearts, 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."
const invalidCard = "1♠";
assertEquals(invalidCard, "Error: Invalid card rank");
const anotherInvalidCard = "Z♠";
assertEquals(anotherInvalidCard, "Error: Invalid card rank");
const emptyCard = "";
assertEquals(emptyCard, "Error: Invalid card rank");
Original file line number Diff line number Diff line change
Expand Up @@ -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(250)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,65 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
test("should return false for an improper fraction", () => {
expect(isProperFraction(5, 2)).toEqual(false);
});

// Case 3: Identify Negative Fractions:
test("should return true for a negative proper fraction", () => {
expect(isProperFraction(-4, 7)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false when numerator equals denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});

// Stretch 1: Identify Negative Denominator:
test("should return true when 2 < |3|", () => {
expect(isProperFraction(2, -3)).toEqual(true);
});

// Stretch 2: Identify Zero Numerator:
test("should return true when 0 < 5", () => {
expect(isProperFraction(0, 5)).toEqual(true);
});

// Stretch 3: Handle Zero Denominator:
// This test checks how the function handles a zero denominator, which is mathematically undefined.
// We expect the function to return false in this case.
test("should return false when 3 > 0", () => {
expect(isProperFraction(3, 0)).toEqual(false);
});

// Stretch 4: Handle Both Numerator and Denominator as Zero:
// This test checks how the function handles both numerator and denominator being zero.
// We expect the function to return false in this case as well.
test("should return false when both numerator and denominator are zero", () => {
expect(isProperFraction(0, 0)).toEqual(false);
});

// Stretch 5: Identify Negative Numerator and Negative Denominator:
test("should return true when |3| < |5|", () => {
expect(isProperFraction(-3, -5)).toEqual(true);
});

// Stretch 6: Identify Improper Negative Numerator and Negative Denominator:
test("should return false when |3| > |2|", () => {
expect(isProperFraction(-3, -2)).toEqual(false);
});

// Stretch 7: Identify Decimal Values:
test("should return true when 2.5 < 3.5", () => {
expect(isProperFraction(2.5, 3.5)).toEqual(true);
});

// Stretch 8: Identify Improper Decimal Values:
test("should return false when 3.5 > 2.5", () => {
expect(isProperFraction(3.5, 2.5)).toEqual(false);
});

// Stretch 9: Identify invalid Inputs (Non-numeric Values):
test("should return false for non-numeric inputs", () => {
expect(isProperFraction("a", 2)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,55 @@
const getCardValue = require("../implement/3-get-card-value");

test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
const aceOfSpades = getCardValue("A♠");
expect(aceOfSpades).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
test("should return 9 for Nine of Hearts", () => {
const nineOfHearts = getCardValue("9♥");
expect(nineOfHearts).toEqual(9);
});
test("should return 5 for Five of Hearts", () => {
const fiveOfHearts = getCardValue("5♥");
expect(fiveOfHearts).toEqual(5);
});
test("should return 2 for Two of Diamonds", () => {
const twoOfDiamonds = getCardValue("2♦");
expect(twoOfDiamonds).toEqual(2);
});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for King of Diamonds", () => {
const kingOfDiamonds = getCardValue("K♦");
expect(kingOfDiamonds).toEqual(10);
});
test("should return 10 for Queen of Clubs", () => {
const queenOfClubs = getCardValue("Q♣");
expect(queenOfClubs).toEqual(10);
});
test("should return 10 for Jack of Hearts", () => {
const jackOfHearts = getCardValue("J♥");
expect(jackOfHearts).toEqual(10);
});
test("should return 10 for Ten of Spades", () => {
const tenOfSpades = getCardValue("10♠");
expect(tenOfSpades).toEqual(10);
});
// Case 4: Handle Ace (A):
test("should return 11 for Ace of Hearts", () => {
const aceOfHearts = getCardValue("A♥");
expect(aceOfHearts).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should throw an error for invalid card rank", () => {
const invalidCard = getCardValue("1♠");
expect(invalidCard).toEqual("Error: Invalid card rank");
});
test("should throw an error for another invalid card rank", () => {
const anotherInvalidCard = getCardValue("Z♠");
expect(anotherInvalidCard).toEqual("Error: Invalid card rank");
});
test("should throw an error for empty card string", () => {
const emptyCard = getCardValue("");
expect(emptyCard).toEqual("Error: Invalid card rank");
});
Loading