Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 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
3c8fe4f
adding more tests for different types of input
TzeMingHo Oct 8, 2025
6166064
simplified return statement in proper-fractoin
TzeMingHo Oct 8, 2025
4b1ad2d
adding tests and condition checks for different types of input
TzeMingHo Oct 8, 2025
892f63b
updated assertion tests and added input type tests for card value
TzeMingHo Oct 8, 2025
f14ee5c
restore package-lock.json from origin/main
TzeMingHo Oct 8, 2025
76ad0cc
made the Error message simplier
TzeMingHo Oct 11, 2025
8b8773c
tried simplified the condition checks in get angle type
TzeMingHo Oct 11, 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if I run the test with:

  • angle: 'ten'
  • angle: 1000
  • angle: -22
  • angle: null

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,42 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you are going with this. :)
It can be simplified to this:

if (angle === null || isNaN(Number(angle))) {
  return "Input should be a number or a number in string";
}

⏫ You don't have to modify your code - I am simply pointing out a small improvement for 'next time' you do something similar to this.

angle === null ||
(typeof angle !== "number" && typeof angle !== "string")
) {
return "Input should be a number or a number in string";
}
angle = Number(angle);
if (isNaN(angle)) {
return "Input should be a number or a number in string";
}
if (angle < 0 || angle > 360) {
return "Angle should be between 0 and 360";
}
if (angle === 0) {
return "Zero 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";
}
if (angle === 360) {
return "Full rotation";
}
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -51,13 +82,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,9 +8,13 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your isProperFraction works well. However, if you wanted to simplify it even more, you could try:

// this will return either true or false
return (Math.abs(numerator) < Math.abs(denominator));

if (numerator < denominator) {
return true;
}
if (typeof numerator !== "number" && typeof numerator !== "string")
return false;
if (typeof denominator !== "number" && typeof denominator !== "string")
return false;
if (isNaN(numerator) || isNaN(denominator)) return false;
if (denominator == 0) return false; // handle zero denominator case
return Math.abs(numerator) < Math.abs(denominator);
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -47,13 +51,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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Good job making sure that 'unhappy path' is tested.

assertEquals(invalidInputs, false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run your tests, I get this result:
Assertion failed: Expected 1♠ to equal Error: Invalid card rank
Assertion failed: Expected Z♠ to equal Error: Invalid card rank
Assertion failed: Expected to equal Error: Invalid card rank

Can you take a look?

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@
// 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 errorMessage =
"Error: Invalid card rank. Input should be a string in the format 'R♠', where R is 2-10, J, Q, K, or A, followed by either ♠, ♥, ♦, or ♣.";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest keeping the error message simple here:
'Error: Invalid card rank'

Right now, your tests are failing because the message you are expecting isn't the same as the one you are receiving. If you change the error message to 'Error: Invalid rank', it should pass correctly.

💡 Make sure that you run your tests before you submit your PR.

Image


if (typeof card !== "string" || card.length < 2) {
return errorMessage;
}
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 errorMessage;
}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -31,27 +46,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 = getCardValue("1♠");
assertEquals(invalidCard, "Error: Invalid card rank");
const anotherInvalidCard = getCardValue("Z♠");
assertEquals(anotherInvalidCard, "Error: Invalid card rank");
const emptyCard = getCardValue("");
assertEquals(emptyCard, "Error: Invalid card rank");
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,103 @@ 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");
});

// Case 6: Identify Full Rotation:
// When the angle is exactly 360 degrees,
// Then the function should return "Full rotation"
test("should identify full rotation (360°)", () => {
expect(getAngleType(360)).toEqual("Full rotation");
});

// Case 7: input is a number in string
test("should return as usual when input is a number in string", () => {
expect(getAngleType("90")).toEqual("Right angle");
});

// Case 8: input is not a number
test("should return 'Input should be a number or a number in string' when input is not a number", () => {
expect(getAngleType("hello")).toEqual(
"Input should be a number or a number in string"
);
});

// Case 9: input is less than 0
test("should return 'Angle should be between 0 and 360' when input is less than 0", () => {
expect(getAngleType(-10)).toEqual("Angle should be between 0 and 360");
});

// Case 10: input is greater than 360
test("should return 'Angle should be between 0 and 360' when input is greater than 360", () => {
expect(getAngleType(400)).toEqual("Angle should be between 0 and 360");
});

// Case 11: input is exactly 0
test("should identify zero angle (0°)", () => {
expect(getAngleType(0)).toEqual("Zero angle");
});

// Case 12: input is empty
test("should return 'Input should be a number or a number in string' when input is empty", () => {
expect(getAngleType()).toEqual(
"Input should be a number or a number in string"
);
});

// Case 13: input is null
test("should return 'Input should be a number or a number in string' when input is null", () => {
expect(getAngleType(null)).toEqual(
"Input should be a number or a number in string"
);
});

// Case 14: input is NaN
test("should return 'Input should be a number or a number in string' when input is NaN", () => {
expect(getAngleType(NaN)).toEqual(
"Input should be a number or a number in string"
);
});

// Case 15: input is undefined
test("should return 'Input should be a number or a number in string' when input is undefined", () => {
expect(getAngleType(undefined)).toEqual(
"Input should be a number or a number in string"
);
});

// Case 16: input is an object
test("should return 'Input should be a number or a number in string' when input is an object", () => {
expect(getAngleType({})).toEqual(
"Input should be a number or a number in string"
);
});

// Case 17: input is an array
test("should return 'Input should be a number or a number in string' when input is an array", () => {
expect(getAngleType([])).toEqual(
"Input should be a number or a number in string"
);
});
Loading