Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26fd354
changed the name of the string in the function
asaniDev Oct 13, 2025
5ab6322
removed line 10 and passed function to console
asaniDev Oct 13, 2025
0c7cc6f
corrected the error with the function
asaniDev Oct 14, 2025
cc216e1
added a return to the function
asaniDev Oct 14, 2025
90013dc
moved the return command to the line below it
asaniDev Oct 14, 2025
f63f7cf
created a function that returns the bmi
asaniDev Oct 14, 2025
a02b0c5
created a function that converts a given string to snake case
asaniDev Oct 14, 2025
e097316
created a toPounds function to return a pounds and pence notation
asaniDev Oct 16, 2025
742c228
answered all the questions in the exercise
asaniDev Oct 16, 2025
0d5ad45
wrote tests for any edge cases and fixed resulting bugs
asaniDev Oct 17, 2025
2038048
made a function for angle types and added tests for all angles
asaniDev Oct 19, 2025
7daf16b
added tests for most fraction types and conditions for them as well
asaniDev Oct 22, 2025
dfebb97
added conditions for all ranks in a deck of cards and tests for them
asaniDev Oct 22, 2025
6865348
added jest tests for all angle types
asaniDev Oct 22, 2025
43d650c
added jest tests for different card values
asaniDev Oct 22, 2025
3ca95c6
took away comment on line 30
asaniDev Oct 22, 2025
c56bd67
revert multiple commits that were from sprint 2
asaniDev Oct 27, 2025
2765c49
added tests for multiple samples, removed a test for ace of spades, c…
asaniDev Oct 29, 2025
035e27e
removed check for ace of spades, adjusted rank to give the full value…
asaniDev Oct 29, 2025
50ee9ef
corrected test for numerator is 0 to a proper fraction, and removed u…
asaniDev Nov 17, 2025
bcbd867
added a regex to make sure only exact number card value matches will …
asaniDev Nov 17, 2025
137fd7c
added a few tests for negative improper fractions
asaniDev Nov 17, 2025
e5b18e4
added more tests to make the test suites more robust, moved ten to nu…
asaniDev Nov 17, 2025
5fa3d08
removed console.log used for testing.
asaniDev Nov 17, 2025
d58910a
used regex pattern to check for ranks and removed includes method
asaniDev Nov 20, 2025
8b52886
added dev dependencies
asaniDev Nov 20, 2025
78f21df
revert changes to sprint 2 folder
asaniDev Nov 22, 2025
8ad9d08
reverted changes to 1.js
asaniDev Nov 22, 2025
14ddfad
reverted changes to 2.js in sprint 2 file.
asaniDev Nov 22, 2025
1a5aada
revert unwanted change
asaniDev Nov 22, 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 @@ -10,9 +10,17 @@
function getAngleType(angle) {
if (angle === 90) {
return "Right angle";
} else if (angle < 90) {
return "Acute 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";
}
// 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.
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -51,13 +59,16 @@ 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(270);
assertEquals(reflex, "Reflex angle");
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

function isProperFraction(numerator, denominator) {
if (numerator < denominator) {
const absNumerator = Math.abs(numerator);
const absDenominator = Math.abs(denominator);

if (absDenominator === 0) {
return `you cannot have zero as a denominator`;
}

if (absNumerator < absDenominator) {
return true;
}

return false;
}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -45,15 +54,24 @@ assertEquals(improperFraction, false);
// Input: numerator = -4, denominator = 7
// 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);
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?
//we can test if the numerator is 0
const zeroFraction = isProperFraction(0, 4);
assertEquals(zeroFraction, true);

//we can test if the denominator is 0
const indefiniteFraction = isProperFraction(3, 0);
assertEquals(indefiniteFraction, `you cannot have zero as a denominator`);
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@
// 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") {
function strictNumber(rank) {
if (/^(0|[1-9][0-9]*)$/.test(rank)) {
return true;
}
return false;
}

const pattern = /^(?:[2-9]|10)$/;
let rank = card.slice(0, card.length - 1);

if (strictNumber(rank)) {
if (pattern.test(Number(rank))) {
return Number(rank);
}
}
Comment on lines +21 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the outer if statement necessary?


const faceCardPattern = /^[JQK]$/;

if (faceCardPattern.test(rank)) {
return 10;
} else if (/^A$/.test(rank)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also just write rank == 'A'.

return 11;
} else {
return "Invalid card rank.";
}
}

console.log(`Jack will give ${getCardValue("J♥")}`);
// The line below allows us to load the getCardValue function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getCardValue;
Expand All @@ -38,20 +60,25 @@ assertEquals(aceofSpades, 11);
// 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 fiveofHearts = getCardValue("9♥");
// ====> write your test here, and then add a line to pass the test in the function above

assertEquals(fiveofHearts, 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 faceCards = getCardValue("J♥");
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."
const invalidCard = getCardValue("100♠");
assertEquals(invalidCard, "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° && 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° && < 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ test("should return true for a proper fraction", () => {
});

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

// Case 3: Identify Negative Fractions:
test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
expect(isProperFraction(-3, 8)).toEqual(true);
expect(isProperFraction(-3, -8)).toEqual(true);
expect(isProperFraction(3, -8)).toEqual(true);
expect(isProperFraction(3, 8)).toEqual(true);
});

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for an equal fraction", () => {
expect(isProperFraction(4, 4)).toEqual(false);
expect(isProperFraction(-7, -7)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@
// We will use the same function, but write tests for it using Jest in this file.
const getCardValue = require("../implement/3-get-card-value");

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

// Case 2: Handle Number Cards (2-10):
test("should return a number matching the rank value for number cards", () => {
expect(getCardValue("2♠")).toEqual(2);
expect(getCardValue("3◆")).toEqual(3);
expect(getCardValue("10♥")).toEqual(10);
expect(getCardValue("9♠")).toEqual(9);
expect(getCardValue("7♥")).toEqual(7);
});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for Face Cards", () => {
expect(getCardValue("J♠")).toEqual(10);
expect(getCardValue("Q◆")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});
// Case 4: Handle Ace (A):
test("should return 11 for Ace", () => {
const aceCard = getCardValue("A◆");
expect(aceCard).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should return invalid card rank for cards that are not in the suite", () => {
expect(getCardValue("100♠")).toEqual("Invalid card rank.");
expect(getCardValue("3.1416◆")).toEqual("Invalid card rank.");
expect(getCardValue("10.9♥")).toEqual("Invalid card rank.");
expect(getCardValue("09♠")).toEqual("Invalid card rank.");
expect(getCardValue("7+♥")).toEqual("Invalid card rank.");
});
Loading