Skip to content
Draft
41 changes: 38 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
node_modules
# Generated .gitignore file for: Node, JavaScript
# Created with FOSSA's DevOps Tools

# Node
node_modules/
npm-debug.log
yarn-error.log
.env
.DS_Store
.vscode
**/.DS_Store
dist/
.cache/
coverage/

# JavaScript
# Add JavaScript-specific ignores here
package-lock.json

# Notebooks and documentation
docs/

# Common
.DS_Store
Thumbs.db
*.log
*.bak
*.tmp
*.swp
*~

# IDE and editor generated files
.idea/
*.sublime-*
.vscode/
.devcontainer/

# Local environment files
.env
.env.local
.env.*.local
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,35 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

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.
if (angle === 90) return "Right angle";
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.
// This will be useful in the "rewrite tests with jest" step.
module.exports = getAngleType;

// 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 an angle in degrees,
// When the function getAngleType is called with this angle,
// Then it should:

// Case 1: Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"
const right = getAngleType(90);
assertEquals(right, "Right angle");

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "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"
const obtuse = getAngleType(120);
// ====> 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

// 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
// Case 1: Identify Right Angles (90°)
assertEquals(getAngleType(90), "Right angle");

// Case 2: Identify Acute Angles (< 90°)
assertEquals(getAngleType(45), "Acute angle");

// Case 3: Identify Obtuse Angles (> 90° and < 180°)
assertEquals(getAngleType(120), "Obtuse angle");

// Case 4: Identify Straight Angles (180°)
assertEquals(getAngleType(180), "Straight angle");

// Case 5: Identify Reflex Angles (> 180° and < 360°)
assertEquals(getAngleType(270), "Reflex angle");

console.log("✅ All tests passed!");
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,28 @@
// write one test at a time, and make it pass, build your solution up methodically

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

// The line below allows us to load the isProperFraction function into tests in other files.
// This will be useful in the "rewrite tests with jest" step.
module.exports = isProperFraction;

// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// Acceptance criteria:

// Proper Fraction check:
// Input: numerator = 2, denominator = 3
// target output: true
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
const properFraction = isProperFraction(2, 3);
assertEquals(properFraction, true);

// Improper Fraction check:
// Input: numerator = 5, denominator = 2
// target output: false
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
const improperFraction = isProperFraction(5, 2);
assertEquals(improperFraction, false);

// Negative Fraction check:
// 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);
// ====> complete with your assertion

// 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

// Stretch:
// What other scenarios could you test for?
// Proper Fraction: 2/3 → true
assertEquals(isProperFraction(2, 3), true);

// Improper Fraction: 5/2 → false
assertEquals(isProperFraction(5, 2), false);

// Negative Fraction: -4/7 → true (absolute value < denominator)
assertEquals(isProperFraction(-4, 7), true);

// Equal Numerator and Denominator: 3/3 → false
assertEquals(isProperFraction(3, 3), false);

console.log("✅ All tests passed!");
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,46 @@
// 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 rank = card.slice(0, -1);
if (rank === "A") return 11;
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
const numValue = parseInt(rank);
if (numValue >= 2 && numValue <= 9) return numValue;
throw new Error("Invalid card rank");
}

// 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;

// 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);

// 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♥");
// ====> 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.

// 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.

// 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."

// Ace → 11
assertEquals(getCardValue("A♠"), 11);

// Number Cards → numeric value
assertEquals(getCardValue("5♥"), 5);
assertEquals(getCardValue("2♦"), 2);
assertEquals(getCardValue("9♣"), 9);

// Face Cards (J, Q, K, 10) → 10
assertEquals(getCardValue("K♥"), 10);
assertEquals(getCardValue("Q♠"), 10);
assertEquals(getCardValue("J♦"), 10);
assertEquals(getCardValue("10♣"), 10);

// Ace (all suits) → 11
assertEquals(getCardValue("A♥"), 11);

// Invalid Card → throw error
try {
getCardValue("X♠");
console.assert(false, "Should have thrown an error for invalid card");
} catch (error) {
assertEquals(error.message, "Invalid card rank");
}

console.log("✅ All tests passed!");
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
// This statement loads the getAngleType function you wrote in the implement directory.
// We will use the same function, but write tests for it using Jest in this file.
const getAngleType = require("../implement/1-get-angle-type");

test("should identify right angle (90°)", () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// REPLACE the comments with the tests
// make your test descriptions as clear and readable as possible

// 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");
expect(getAngleType(30)).toEqual("Acute angle");
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(89)).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");
expect(getAngleType(135)).toEqual("Obtuse angle");
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).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");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
expect(getAngleType(200)).toEqual("Reflex angle");
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// This statement loads the isProperFraction function you wrote in the implement directory.
// We will use the same function, but write tests for it using Jest in this file.
const isProperFraction = require("../implement/2-is-proper-fraction");

test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});

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

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false when numerator equals denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
expect(isProperFraction(1, 1)).toEqual(false);
expect(isProperFraction(100, 100)).toEqual(false);
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
// This statement loads the getCardValue function you wrote in the implement directory.
// 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);
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:
test("should return correct value for number cards (2-9)", () => {
expect(getCardValue("2♦")).toEqual(2);
expect(getCardValue("3♣")).toEqual(3);
expect(getCardValue("4♥")).toEqual(4);
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("6♠")).toEqual(6);
expect(getCardValue("7♦")).toEqual(7);
expect(getCardValue("8♣")).toEqual(8);
expect(getCardValue("9♥")).toEqual(9);
});

test("should return 10 for face cards (J, Q, K, 10)", () => {
expect(getCardValue("10♣")).toEqual(10);
expect(getCardValue("J♦")).toEqual(10);
expect(getCardValue("Q♠")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});

test("should return 11 for all Aces", () => {
expect(getCardValue("A♠")).toEqual(11);
expect(getCardValue("A♥")).toEqual(11);
expect(getCardValue("A♦")).toEqual(11);
expect(getCardValue("A♣")).toEqual(11);
});

test("should throw an error for invalid card rank", () => {
expect(() => getCardValue("X♠")).toThrow("Invalid card rank");
expect(() => getCardValue("Z♥")).toThrow("Invalid card rank");
expect(() => getCardValue("11♦")).toThrow("Invalid card rank");
expect(() => getCardValue("0♣")).toThrow("Invalid card rank");
});
Loading