Skip to content

Sheffield | May-2025 | WALEED-YAHYA SALIH-TAHA | Sprint-3 #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
56e3dbc
1. identified acute angel and it's function
Bluejay600 Jun 14, 2025
d4a0730
Identified Obtuse Angles when the angle is greater than 90 and less t…
Bluejay600 Jul 5, 2025
f6cd051
Identified Stright Angle s when the angle is 180 degree
Bluejay600 Jul 5, 2025
59a1e19
Identified stright angle when the angle is greater than 180
Bluejay600 Jul 5, 2025
a0004a8
1. Added 4 if conditions to the function getAngleType(angle).
Bluejay600 Jul 6, 2025
c7772a6
Merge branch 'Sprint3-Test-branch' of https://github.com/Bluejay600/M…
Bluejay600 Jul 6, 2025
eb50828
1. Added a test line to each case.
Bluejay600 Jul 6, 2025
b797a92
added a false return value to handle the case for improper fractions
Bluejay600 Jul 6, 2025
f5f36f5
1. wrote test, and make it pass, to build solution up methodically.
Bluejay600 Jul 7, 2025
a467519
Added 4 if conditions in the function getAngleType(angle) to build up…
Bluejay600 Jul 7, 2025
18a93a1
Added a return invalid angle to handle angles outside the range of 0 …
Bluejay600 Jul 7, 2025
3523e59
Identified and corrected the right angle when the angle is exactly 90…
Bluejay600 Jul 7, 2025
d6a2edf
Added assertion to the negative fraction to equal true.
Bluejay600 Jul 7, 2025
67a05da
Added assertion to the equal numerator and denominator, and a console…
Bluejay600 Jul 7, 2025
5a1570a
Stretched creating Zero Numerator check assertion.
Bluejay600 Jul 7, 2025
61decd0
implemented the function getCardValue(card) and added if conditions t…
Bluejay600 Jul 7, 2025
8e295aa
wrote the test code and added a line to pass the test.
Bluejay600 Jul 7, 2025
4b2e240
fixed the getCardValue function to handel card 10
Bluejay600 Jul 7, 2025
a1f0f58
Handled face Cards (J, Q, K) to return the value 10.
Bluejay600 Jul 7, 2025
ec30fb1
Added a code to handle a card with invalid rank (Z)
Bluejay600 Jul 7, 2025
a0595c0
Replaced the code my code in 1-key-implement and tested
Bluejay600 Jul 7, 2025
eda20da
Merge branch 'Sprint3-Test-branch' of https://github.com/Bluejay600/M…
Bluejay600 Jul 7, 2025
b0904d1
fixed acute angle test code to make the description clear.
Bluejay600 Jul 8, 2025
fca4456
removed the duplicated test for Acute angle
Bluejay600 Jul 8, 2025
71bac2d
1. removed unwanted spaces.
Bluejay600 Jul 9, 2025
3e96df9
1. removed the function and replaced with the function in the 1-key-i…
Bluejay600 Jul 10, 2025
2b1c9be
1. Replaced the comment and added angle 45 in the function.
Bluejay600 Jul 10, 2025
3a5be71
1. Identified Obtuse angles (90 < angle < 180 )
Bluejay600 Jul 10, 2025
da42c37
1. Identified reflex angles when angle is greater than 180 and less t…
Bluejay600 Jul 10, 2025
c9b0ff6
1. Identified Invalid angle when it's less than 0 or greater than 360.
Bluejay600 Jul 10, 2025
fd37f69
1. identified right angle.
Bluejay600 Jul 10, 2025
f242d6a
1. removed the extra space between test and the opening parenthesis:
Bluejay600 Jul 10, 2025
fee695d
added my completed function from key-implement.
Bluejay600 Jul 10, 2025
abcdfbf
identified improper fractions to case 2.
Bluejay600 Jul 10, 2025
af20de9
replaced the whole code with the one in card value in key-implement.
Bluejay600 Jul 10, 2025
7076fc0
Handled Number Cards (2-10):
Bluejay600 Jul 10, 2025
9ef7886
1. Handled Face Cards (J, Q, K):
Bluejay600 Jul 10, 2025
1b10f2d
handled invalid cards.
Bluejay600 Jul 10, 2025
7d4ba19
joined the two Ace functions in one.
Bluejay600 Jul 10, 2025
49b7c00
initialized counter to keep track of occurrences
Bluejay600 Jul 10, 2025
f85e00c
1. initialized a counter for the function.
Bluejay600 Jul 10, 2025
f3973af
Added test tarbet string
Bluejay600 Jul 10, 2025
3b2251a
added a test to Handle count of 0.
Bluejay600 Jul 10, 2025
58a71c3
Added a test to handle a negative count.
Bluejay600 Jul 10, 2025
1a74ee8
Implemented a function repeat that that given a target string str and…
Bluejay600 Jul 10, 2025
ebc99d8
Function was handling the case for 1st. I expanded to handle other n…
Bluejay600 Jul 10, 2025
af1e3ca
implemented case one and case 2 testing.
Bluejay600 Jul 11, 2025
cab246a
Merge branch 'CodeYourFuture:main' into Sprint3-Test-branch
Bluejay600 Jul 11, 2025
a64cee4
Played computer with the password validator
Bluejay600 Jul 11, 2025
a451aeb
Merge branch 'Sprint3-Test-branch' of https://github.com/Bluejay600/M…
Bluejay600 Jul 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
18 changes: 14 additions & 4 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

function getAngleType(angle) {
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";
return "Invalid angle"; // Added to handle angles outside the range of 0 to 360 degrees
// read to the end, complete line 36, then pass your test here
}

Expand All @@ -19,6 +24,7 @@ function assertEquals(actualOutput, targetOutput) {
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
return actualOutput === targetOutput; // Return true if the assertion passes
}

// Acceptance criteria:
Expand All @@ -30,8 +36,7 @@ function assertEquals(actualOutput, targetOutput) {
// 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");
assertEquals(getAngleType(90), "Right angle");

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
Expand All @@ -42,15 +47,20 @@ 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
const obtuse = getAngleType(120);
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");
18 changes: 13 additions & 5 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (denominator === 0) return false; // Can't divide by zero
return Math.abs(numerator) < Math.abs(denominator);
}


// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
Expand All @@ -25,15 +27,13 @@ function assertEquals(actualOutput, targetOutput) {
// 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);
assertEquals(isProperFraction(2, 3), true); // ✅ should pass

// 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);
assertEquals(isProperFraction(5, 2), false); // ✅ should pass

// Negative Fraction check:
// Input: numerator = -4, denominator = 7
Expand All @@ -47,7 +47,15 @@ const negativeFraction = isProperFraction(-4, 7);
// 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);
assertEquals(equalFraction, false);
// ====> complete with your assertion

// Stretch:
// What other scenarios could you test for?
// Zero Numerator check:
// Input: numerator = 0, denominator = 5
// target output: true
// Explanation: The fraction 0/5 is a proper fraction because the numerator is zero,
// which is less than the denominator. The function should return true.
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true); // ✅ should pass
20 changes: 20 additions & 0 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
// 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 rank = card.slice(0, -1); // Get the rank (everything except the last character)
if (rank === "A") return 11;
if (["J", "Q", "K"].includes(rank)) return 10;
if (rank >= "2" && rank <= "9") return parseInt(rank, 10);
if (rank === "10") return 10; // Handle the 10 card explicitly
throw new Error("Invalid card rank");
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -34,18 +39,33 @@ assertEquals(aceofSpades, 11);
// 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
assertEquals(fiveofHearts, 5);

// 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 jackOfDiamonds = getCardValue("J♦");
assertEquals(jackOfDiamonds, 10);
const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);
const kingOfSpades = getCardValue("K♠");
assertEquals(kingOfSpades, 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.
// (Note: In some games, the Ace can also be worth 1 point, but for this function, we will assume it is always worth 11 points.)
const aceOfDiamonds = getCardValue("A♦");
assertEquals(aceOfDiamonds, 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."
try {
getCardValue("Z♠"); // Invalid card
} catch (error) {
console.assert(error.message === "Invalid card rank", "Expected error for invalid card rank");
}
26 changes: 16 additions & 10 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

}





if (angle <= 0 || angle >= 360) return "Invalid angle";
if (angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
return "Reflex angle"; // angle between 180 and 360
};



// Don't get bogged down in this detail
// Jest uses CommonJS module syntax by default as it's quite old
// We will upgrade our approach to ES6 modules in the next course module, so for now
// we have just written the CommonJS module.exports syntax for you
module.exports = getAngleType;
module.exports = getAngleType;
console.log(getAngleType(45)); // Acute angle
console.log(getAngleType(90)); // Right angle
console.log(getAngleType(135)); // Obtuse angle
console.log(getAngleType(180)); // Straight angle
console.log(getAngleType(270)); // Reflex angle
console.log(getAngleType(0)); // Invalid angle
console.log(getAngleType(360)); // Invalid angle
console.log(getAngleType(-10)); // Invalid angle
Comment on lines +17 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused code or code used solely for development purposes should be removed or, at the very least, commented out with clear justification.

39 changes: 28 additions & 11 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
const getAngleType = require("./1-get-angle-type");

// Case 1: Identify Right Angles
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"

// 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"
// Case 2: Identify Acute Angles (less than 90°)
test("should identify acute angles (< 90°)", () => {
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});

// Case 3: Identify Obtuse Angles (90° < angle < 180°)
test("should identify obtuse angles (between 90° and 180°)", () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(135)).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("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("reflex angle (181°)", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});
// Case 6: Handle invalid angles (≤ 0 or ≥ 360)
test("should identify invalid angles (≤ 0 or ≥ 360)", () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-45)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(400)).toEqual("Invalid angle");
});
49 changes: 49 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,54 @@ function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
}
function isProperFraction(numerator, denominator) {
if (denominator === 0) return false; // Can't divide by zero
return Math.abs(numerator) < Math.abs(denominator);
}


// here's our helper again
function assertEquals(actualOutput, targetOutput) {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
}
// 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.
assertEquals(isProperFraction(2, 3), true); // ✅ should pass

// 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.
assertEquals(isProperFraction(5, 2), false); // ✅ should pass

// 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);
assertEquals(equalFraction, false);
// ====> complete with your assertion

// Stretch:
// What other scenarios could you test for?
// Zero Numerator check:
// Input: numerator = 0, denominator = 5
// target output: true
// Explanation: The fraction 0/5 is a proper fraction because the numerator is zero,
// which is less than the denominator. The function should return true.
const zeroNumerator = isProperFraction(0, 5);
assertEquals(zeroNumerator, true); // ✅ should pass
Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically 0 is not considered a proper fraction. :)


module.exports = isProperFraction;
9 changes: 9 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => {
});

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

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for equal numerator and denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
71 changes: 69 additions & 2 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck

// You will need to implement a function getCardValue
// the function takes a single parameter, a string representing a playing card
// the function should return the numerical value of the card
// the first test and first case is written for you
// complete the rest of the tests and cases
// 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) {
// replace with your code from key-implement
return 11;
const rank = card.slice(0, -1); // Get the rank (everything except the last character)
if (rank === "A") return 11;
if (["J", "Q", "K"].includes(rank)) return 10;
if (rank >= "2" && rank <= "9") return parseInt(rank, 10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Strings are compared differently in the JS language.

Does your function return the value you expected from each of the following function calls?

getCardValue("333♠");
getCardValue("3.1416♠");
getCardValue("3ABC♠");

if (rank === "10") return 10; // Handle the 10 card explicitly
throw new Error("Invalid card rank");
}

// 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
assertEquals(fiveofHearts, 5);

// 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 jackOfDiamonds = getCardValue("J♦");
assertEquals(jackOfDiamonds, 10);
const queenOfClubs = getCardValue("Q♣");
assertEquals(queenOfClubs, 10);
const kingOfSpades = getCardValue("K♠");
assertEquals(kingOfSpades, 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.
// (Note: In some games, the Ace can also be worth 1 point, but for this function, we will assume it is always worth 11 points.)
const aceOfDiamonds = getCardValue("A♦");
assertEquals(aceOfDiamonds, 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."
try {
getCardValue("Z♠"); // Invalid card
} catch (error) {
console.assert(error.message === "Invalid card rank", "Expected error for invalid card rank");
}
module.exports = getCardValue;
Loading