Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aeba164
Explained what line 3 is doing
sayeedhussain01 Jun 17, 2026
bf0aa49
Fix syntax error
sayeedhussain01 Jun 26, 2026
f09ff4b
fix syntax error and define erro
sayeedhussain01 Jun 26, 2026
28dec16
fix syntax error and used valid parameter name
sayeedhussain01 Jun 26, 2026
fbc18f9
fixed multiply function to return result
sayeedhussain01 Jun 26, 2026
82ad98f
fixed sum function to return correct value
sayeedhussain01 Jun 26, 2026
9e3b8c1
fix getLastDigit to return last digit of any input number
sayeedhussain01 Jun 26, 2026
df45294
made a bmi calcultor function
sayeedhussain01 Jun 26, 2026
9513e24
wrote a function for upper snakecase
sayeedhussain01 Jun 26, 2026
09bd32f
added function
sayeedhussain01 Jun 26, 2026
64a649f
Answered following question in time format
sayeedhussain01 Jul 10, 2026
19b4504
converted 24 clock to 12 and test group of input and adge cases
sayeedhussain01 Jul 10, 2026
1f54745
fix original files
sayeedhussain01 Jul 11, 2026
4cd4749
Implement angle
sayeedhussain01 Jul 18, 2026
f86d67d
Implemented angle type
sayeedhussain01 Jul 18, 2026
c52dab3
Implemented angle type
sayeedhussain01 Jul 18, 2026
e207d39
Formed proper fraction
sayeedhussain01 Jul 20, 2026
833f478
implemented card value
sayeedhussain01 Jul 24, 2026
5935475
angle type test done
sayeedhussain01 Jul 28, 2026
d6b8042
get angle test done
sayeedhussain01 Jul 28, 2026
0b6ad14
get angle test done
sayeedhussain01 Jul 28, 2026
563050e
get angle test done
sayeedhussain01 Jul 28, 2026
bd91f3b
proper fraction test implementation done
sayeedhussain01 Jul 29, 2026
9cf30f5
card value test implementation done
sayeedhussain01 Jul 29, 2026
d3ca5ad
try to fix
sayeedhussain01 Jul 29, 2026
d58e208
fix error
sayeedhussain01 Jul 29, 2026
9efb8a7
fix revert files
sayeedhussain01 Jul 30, 2026
0b2dbe2
fix revert sprint-1 task
sayeedhussain01 Jul 30, 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
@@ -1,37 +1,59 @@
// Implement a function getAngleType
//
// When given an angle in degrees, it should return a string indicating the type of angle:
// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
// - "Obtuse angle" for angles greater than 90° and less than 180°
// - "Straight angle" for exactly 180°
// - "Reflex angle" for angles greater than 180° and less than 360°
// - "Invalid angle" for angles outside the valid range.

// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.)

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function getAngleType(angle) {
// TODO: Implement this function
}

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

// This helper function is written 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}`
);
}

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
// Implement a function getAngleType
//
// When given an angle in degrees, it should return a string indicating the type of angle:
// - "Acute angle" for angles greater than 0° and less than 90°
// - "Right angle" for exactly 90°
// - "Obtuse angle" for angles greater than 90° and less than 180°
// - "Straight angle" for exactly 180°
// - "Reflex angle" for angles greater than 180° and less than 360°
// - "Invalid angle" for angles outside the valid range.

// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.)

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

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

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

// This helper function is written 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}`
);
}

// TODO: Write tests to cover all cases, including boundary and invalid cases.
// Example: Identify Right Angles
const right = getAngleType(90);
assertEquals(right, "Right angle");
assertEquals(getAngleType(45), "Acute angle");
assertEquals(getAngleType(145), "Obtuse angle");
assertEquals(getAngleType(180), "Straight angle");
assertEquals(getAngleType(190), "Reflex angle");
assertEquals(getAngleType(390), "Invalid");
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
// Implement a function isProperFraction,
// when given two numbers, a numerator and a denominator, it should return true if
// the given numbers form a proper fraction, and false otherwise.

// Assumption: The parameters are valid numbers (not NaN or Infinity).

// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
}

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

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
// Implement a function isProperFraction,
// when given two numbers, a numerator and a denominator, it should return true if
// the given numbers form a proper fraction, and false otherwise.

// Assumption: The parameters are valid numbers (not NaN or Infinity).

// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
let fraction = Math.abs(numerator) < Math.abs(denominator);
return fraction;
}

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

// TODO: Write tests to cover all cases.
// What combinations of numerators and denominators should you test?

// Example: 1/2 is a proper fraction
assertEquals(isProperFraction(1, 2), true);
assertEquals(isProperFraction(5, 2), false);
assertEquals(isProperFraction(7, 9), true);
assertEquals(isProperFraction(3, -5), true);
163 changes: 109 additions & 54 deletions Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,109 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// Implement a function getCardValue, when given a string representing a playing card,
// should return the numerical value of the card.

// A valid card string will contain a rank followed by the suit.
// The rank can be one of the following strings:
// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
// The suit can be one of the following emojis:
// "♠", "♥", "♦", "♣"
// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦".

// When the card is an ace ("A"), the function should return 11.
// When the card is a face card ("J", "Q", "K"), the function should return 10.
// When the card is a number card ("2" to "10"), the function should return its numeric value.

// When the card string is invalid (not following the above format), the function should
// throw an error.

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

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

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

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);

// Handling invalid cards
try {
getCardValue("invalid");

// 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 🎉");
}

// What other invalid card cases can you think of?
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// Implement a function getCardValue, when given a string representing a playing card,
// should return the numerical value of the card.

// A valid card string will contain a rank followed by the suit.
// The rank can be one of the following strings:
// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
// The suit can be one of the following emojis:
// "♠", "♥", "♦", "♣"
// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦".

// When the card is an ace ("A"), the function should return 11.
// When the card is a face card ("J", "Q", "K"), the function should return 10.
// When the card is a number card ("2" to "10"), the function should return its numeric value.

// When the card string is invalid (not following the above format), the function should
// throw an error.

// Acceptance criteria:
// After you have implemented the function, write tests to cover all the cases, and
// execute the code to ensure all tests pass.

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

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

const rank1 = card.slice(0, -1);
const suit1 = card.slice(-1);
const IsEqualCard = suits.includes(suit1) && ranks.includes(rank1);
if (!IsEqualCard) {
throw new Error("invalid card ");
}
if (rank1 === "A") {
return 11;
}
if (rank1 === "J" || rank1 === "Q" || rank1 === "K") {
return 10;
}
const numberRanks = Number(rank1);
if (numberRanks >= 2 && numberRanks <= 10) {
return numberRanks;
}
}

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

// Helper functions to make our assertions easier to read.
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}

// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
// Examples:
assertEquals(getCardValue("9♠"), 9);
assertEquals(getCardValue("10♦"), 10);
assertEquals(getCardValue("7♠"), 7);
assertEquals(getCardValue("8♥"), 8);
assertEquals(getCardValue("A♥"), 11);
assertEquals(getCardValue("J♥"), 10);
assertEquals(getCardValue("Q♥"), 10);
assertEquals(getCardValue("K♥"), 10);

// Handling invalid cards
try {
getCardValue("invalid");

// 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("1♠");
console.error("Error was not thrown 😢");
} catch (e) {
console.log("Error thrown for invalid 🎉");
}

try {
getCardValue("error");
console.error("Error was not thrown 😢");
} catch (e) {
console.log("Error thrown for invalid 🎉");
}

// What other invalid card cases can you think of?
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
// 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");

// TODO: Write tests in Jest syntax to cover all cases/outcomes,
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
// Case 3: Obtuse angles
// Case 4: Straight angle
// Case 5: Reflex angles
// Case 6: Invalid angles
// 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");

// TODO: Write tests in Jest syntax to cover all cases/outcomes,
// including boundary and invalid cases.

// Case 1: Acute angles
test(`should return "Acute angle" when ( angle > 0 and angle < 90)`, () => {
// Test various acute angles, including boundary cases
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 2: Right angle
test(`should return "Right angle" when angle exactly equals 90`, () => {
expect(getAngleType(90)).toEqual("Right angle");
});

// Case 3: Obtuse angles
describe(`should return "obtuse angle" when obtuse > 90 and obtuse < 180`, () => {
expect(getAngleType(95)).toEqual("Obtuse angle");
expect(getAngleType(99)).toEqual("Obtuse angle");
expect(getAngleType(105)).toEqual("Obtuse angle");
});
// Case 4: Straight angle

test(`should return "straight angle" when straight is equals 180`, () => {
expect(getAngleType(180)).toEqual("Straight angle");
});
// Case 5: Reflex angles
test(`should return "reflex angle" if angle is more than 180 and less than 360`, () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(191)).toEqual("Reflex angle");
expect(getAngleType(211)).toEqual("Reflex angle");
});

// tes(`should return "reflex angle" when straight is `);
// Case 6: Invalid angles
test(`should return "invalid angle" if any of them don't match`, () => {
expect(getAngleType(385)).toEqual("Invalid");
expect(getAngleType(380)).toEqual("Invalid");
expect(getAngleType(430)).toEqual("Invalid");
expect(getAngleType(390)).toEqual("Invalid");
});
Loading
Loading