Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7fd7710
capitalize function, str declaration
dona-shehu Jun 16, 2026
88d76b4
Declaration and scope
dona-shehu Jun 16, 2026
b6def45
Function parameters
dona-shehu Jun 16, 2026
d06f9a3
Add return a * b
dona-shehu Jun 17, 2026
c15a48e
Sum function fixed return
dona-shehu Jun 17, 2026
66ddc97
Function with no parameter fixed
dona-shehu Jun 17, 2026
b82f302
Calculate BMI
dona-shehu Jun 17, 2026
491605b
Capitalize function
dona-shehu Jun 17, 2026
b8a684c
Convert pence to pound function
dona-shehu Jun 17, 2026
095f72d
Removed comments
dona-shehu Jun 17, 2026
0a4c587
Add 2p example
dona-shehu Jun 17, 2026
4aa639f
Time format pad()
dona-shehu Jun 17, 2026
892bb92
Fixed variable declaration for bodyMassIndex
dona-shehu Jun 22, 2026
4bc146e
implement, 1-get-angle-type.
dona-shehu Jun 30, 2026
4ccf833
implement, 2-is-proper-fraction
dona-shehu Jun 30, 2026
4b20e69
Implement, 3-get-card-value
dona-shehu Jul 1, 2026
6f270d2
Add comments to tests
dona-shehu Jul 6, 2026
0799ea5
Update error message
dona-shehu Jul 6, 2026
956f635
Add tests in Jest syntax
dona-shehu Jul 6, 2026
5cec9c4
Add test in Jest syntax
dona-shehu Jul 6, 2026
1096cc2
Used array to validate rank & suit
dona-shehu Jul 6, 2026
6caf04c
Add test in Jest syntax
dona-shehu Jul 6, 2026
fdd00ab
Revert accidental changes to Sprint-2 files
dona-shehu Jul 6, 2026
31e40fa
Added default formatter, and more test cases.
dona-shehu Jul 9, 2026
68ce473
Removed last unnecessary else.
dona-shehu Jul 9, 2026
bfe4374
Updated the comments.
dona-shehu Jul 11, 2026
188448b
Removed unnecessary comments.
dona-shehu Jul 11, 2026
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 @@ -16,6 +16,18 @@

function getAngleType(angle) {
// TODO: Implement this function
if (angle > 0 && angle < 90) {
return "Acute angle";
} else if (angle === 90) {
return "Right angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
return "Invalid angle";
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand All @@ -33,5 +45,33 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles

const acute1 = getAngleType(45);
assertEquals(acute1, "Acute angle");

const acute2 = getAngleType(70);
assertEquals(acute2, "Acute angel");

const right = getAngleType(90);
assertEquals(right, "Right angle");

const obtuse1 = getAngleType(120);
assertEquals(obtuse1, "Obtuse angle");

const obtuse2 = getAngleType(165);
assertEquals(obtuse2, "Obtuse angle");

const straight = getAngleType(180);
assertEquals(straight, "Straight angle");

const reflex1 = getAngleType(200);
assertEquals(reflex1, "Reflex angle");

const reflex2 = getAngleType(310);
assertEquals(reflex2, "Reflex angle");

const invalid0 = getAngleType(0);
assertEquals(invalid0, "Invalid angle");

const invalid360 = getAngleType(360);
assertEquals(invalid360, "Invalid angle");
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
if(denominator === 0){
return false;
}
let fraction = numerator / denominator;
return fraction > 0 && fraction < 1;
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand All @@ -31,3 +36,24 @@ function assertEquals(actualOutput, targetOutput) {

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);

// Example: numerator is 0 is a proper fraction
assertEquals(isProperFraction(0, 2), false);

// Example: numerator is equal to denominators is a proper fraction
assertEquals(isProperFraction(2, 2), false);

// Example: denominator is 0 is a proper fraction
assertEquals(isProperFraction(5, 0), false);

// Example: numerator is negative is a proper fraction
assertEquals(isProperFraction(-1, 2), false);

// Example: denominator is negative is a proper fraction
assertEquals(isProperFraction(4, -3), false);

// Example: numerator and denominator are both negative values is a proper fraction
assertEquals(isProperFraction(-5, -6), true);

// Example: negative numerator with smaller value then negative dominator is a proper fraction
assertEquals(isProperFraction(-6, -5), false);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@

function getCardValue(card) {
// TODO: Implement this function

let rank = card.slice(0, -1);
let suit = card.slice(-1);

const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
const validSuits = ["♠", "♥", "♦", "♣"];

let isValidRank = validRanks.includes(rank);
let isValidSuit = validSuits.includes(suit);



// Invalid Card
if( !isValidRank || !isValidSuit ){
throw new Error("Invalid Card")
Comment on lines +30 to +40

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thats a nice way of checking if the input is valid. By expliciting stating all allowed values that code is easy to understand

}

if(rank == "A"){
return 11;
}
else if(rank == "J" || rank == "Q" || rank == "K"){
return 10;
}
else return Number(rank);

}

// The line below allows us to load the getCardValue function into tests in other files.
Expand All @@ -39,8 +64,31 @@ function assertEquals(actualOutput, targetOutput) {

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:

assertEquals(getCardValue("8♠"), 8);

assertEquals(getCardValue("7♠"), 7);

assertEquals(getCardValue("6♠"), 6);

assertEquals(getCardValue("5♠"), 5);

assertEquals(getCardValue("4♠"), 4);

assertEquals(getCardValue("3♠"), 3);

assertEquals(getCardValue("2♠"), 2);

assertEquals(getCardValue("9♠"), 9);

assertEquals(getCardValue("J♠"), 10);

assertEquals(getCardValue("Q♠"), 10);

assertEquals(getCardValue("K♠"), 10);

assertEquals(getCardValue("A♠"), 11);

// Handling invalid cards
try {
getCardValue("invalid");
Expand All @@ -51,4 +99,23 @@ try {
console.log("Error thrown for invalid card 🎉");
}


// What other invalid card cases can you think of?
try {
getCardValue("24♠");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}


try {
getCardValue("44");

// This line will not be reached if an error is thrown as expected
console.error("Error was not thrown for invalid card 😢");
} catch (e) {
console.log("Error thrown for invalid card 🎉");
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
expect(getAngleType(89)).toEqual("Acute angle");
});


// Case 2: Right angle
test(`should return "Right angle" when ( angle = 90)`, () => {
// Test various right angles, including boundary cases
expect(getAngleType(90)).toEqual("Right angle");

});


// Case 3: Obtuse angles
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
// Test various obtuse angles, including boundary cases
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});


// Case 4: Straight angle
test(`should return "Straight angle" when ( angle = 180)`, () => {
// Test various straight angles, including boundary cases
expect(getAngleType(180)).toEqual("Straight angle");
});


// Case 5: Reflex angles
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
// Test various reflex angles, including boundary cases
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(220)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});


// Case 6: Invalid angles
test(`should return "Invalid angle" when (180 < angle < 360)`, () => {
// Test various invalid angles, including boundary cases
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could add 2 test cases that are not boundary cases

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added more test cases that are not boundary cases.

});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,37 @@ const isProperFraction = require("../implement/2-is-proper-fraction");

// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.

// Special case: numerator is zero
// Special case: denominator is zero.
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});

// Special case: numerator is zero.
test(`should return false when numerator is zero`, () => {
expect(isProperFraction(0, 1)).toEqual(false);
});

// Special case: numerator is equal to denominators is not a proper fraction.
test(`should return false when numerator is equal to denominator`, () => {
expect(isProperFraction(2, 2)).toEqual(false);
});

// Special case: numerator is negative is not a proper fraction.
test(`should return false when numerator is negative value`, () => {
expect(isProperFraction(-1, 2)).toEqual(false);
});

// Special case: denominator is negative is not a proper fraction.
test(`should return false denominator is negative value `, () => {
expect(isProperFraction(1, -2)).toEqual(false);
});

// Special case: numerator and denominator are both negative values is a proper fraction.
test(`should return true when numerator ans denominator are both negative values `, () => {
expect(isProperFraction(-5, -6)).toEqual(true);
});

// Special case: negative numerator with smaller value then negative dominator is not a proper fraction
test(`should return false when negative numerator is smaller than negative denominator `, () => {
expect(isProperFraction(-6, -5)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const getCardValue = require("../implement/3-get-card-value");

// TODO: Write tests in Jest syntax to cover all possible outcomes.

// Case 1: Ace (A)
// Case 1: Ace (A) ♣ ♦ ♥ C
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♥")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
});

// Suggestion: Group the remaining test data into these categories:
Expand All @@ -18,3 +21,28 @@ test(`Should return 11 when given an ace card`, () => {
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror

// Number cards
test(`Should return the number when given a number card`, () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("7♥")).toEqual(7);
expect(getCardValue("9♦")).toEqual(9);
expect(getCardValue("6♣")).toEqual(6);
});

// Face Cards (J, Q, K)
test(`Should return 10 when given a face card`, () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q♥")).toEqual(10);
expect(getCardValue("K♦")).toEqual(10);
});

// Invalid Cards
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("1♣")).toThrow("Invalid Card");
expect(() => getCardValue("Z♦")).toThrow("Invalid Card");
expect(() => getCardValue("12♦")).toThrow("Invalid Card");
expect(() => getCardValue("♦3")).toThrow("Invalid Card");
expect(() => getCardValue("")).toThrow("Invalid Card");
expect(() => getCardValue("invalid")).toThrow("Invalid Card");
expect(() => getCardValue("----")).toThrow("Invalid Card");
});
Loading