Skip to content

Glasgow | May-2025 | Salah Ahmed| Sprint-3 #634

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 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
41faaac
have done my key-implement exercise
Millena28 Feb 21, 2025
fb392b3
done the mandatory-rewrite
Millena28 Feb 21, 2025
52148a6
Done the mandatory-practice
Millena28 Feb 27, 2025
4d0497e
Done stretch investigate and implemented new card-validator file
Millena28 Feb 28, 2025
13220cd
done ALL
Millena28 Feb 28, 2025
396094b
made some corrections from review
Millena28 Mar 18, 2025
f3b70e8
Merge branch 'CodeYourFuture:coursework/sprint-3' into coursework/spr…
avatarit Jun 28, 2025
8ca4e8e
Implement angle type identification in getAngleType function
avatarit Jun 28, 2025
a9c9341
Remove placeholder comments for missing tests in getAngleType function
avatarit Jun 28, 2025
b1b2078
Refactor getAngleType function for improved readability and consistency
avatarit Jun 28, 2025
78e3a52
Add assertions for zero numerator check in isProperFraction function
avatarit Jun 28, 2025
c75235c
Fix formatting inconsistencies in angle type assertions for clarity
avatarit Jun 28, 2025
39aad2d
Refactor getCardValue function to improve card rank extraction and va…
avatarit Jun 28, 2025
0d2e786
Refactor getAngleType function to streamline angle classification logic
avatarit Jul 2, 2025
ef3385f
Refactor getCardValue function for improved clarity and error handling
avatarit Jul 2, 2025
f381483
Update package-lock.json to reflect changes in package names and vers…
avatarit Jul 2, 2025
49bcbfe
Refactor isProperFraction function and update tests for accuracy
avatarit Jul 2, 2025
5774458
Remove unnecessary files: package.json, readme.md, and image assets
avatarit Jul 2, 2025
9226863
Add tests for getCardValue function to validate card value retrieval …
avatarit Jul 2, 2025
e8bdd72
Add getCardValue function to retrieve card values with error handling
avatarit Jul 2, 2025
03fd47d
Add tests for getAngleType function to validate angle identification
avatarit Jul 2, 2025
61cdb3e
Implement getAngleType function with angle classification and corresp…
avatarit Jul 2, 2025
41d94fc
Implement isProperFraction function with comprehensive test cases
avatarit Jul 2, 2025
0f70f77
Implement isProperFraction function to evaluate proper fractions
avatarit Jul 2, 2025
830b5e4
Refactor code structure for improved readability and maintainability
avatarit Jul 2, 2025
b500e15
Fix the code of get angle
avatarit Jul 2, 2025
e931299
Remove unnecessary blank line in isProperFraction.js
avatarit Jul 2, 2025
315ab1a
fixed the code issue
avatarit Jul 2, 2025
aae7d84
Remove unnecessary blank line at the beginning of get-card-value.js
avatarit Jul 2, 2025
2fd86de
Refactor angle type function to improve clarity and return default va…
avatarit Jul 2, 2025
c693e17
Refactor angle type tests for clarity by removing redundant comments
avatarit Jul 2, 2025
4330f25
fix the issue in the code
avatarit Jul 2, 2025
d92d35c
Update isProperFraction test file
avatarit Jul 2, 2025
c45f222
Refactor getCardValue function for improved readability by adjusting …
avatarit Jul 2, 2025
388622f
Refactor test cases for getCardValue function by reorganizing comment…
avatarit Jul 2, 2025
51997e1
Update countChar function
avatarit Jul 2, 2025
88e292d
Fix formatting of comment in count.test.js for consistency
avatarit Jul 2, 2025
7829d7e
Refactor getOrdinalNumber function for improved readability by adjust…
avatarit Jul 2, 2025
e924d5d
update ordinal-number.test.js for improved readability
avatarit Jul 2, 2025
475029a
Fix formatting
avatarit Jul 2, 2025
65bcde5
implement the code
avatarit Jul 2, 2025
fef80b8
Refactor isValidCreditCard function for improved readability and cons…
avatarit Jul 3, 2025
9549f29
The questions have been answerd
avatarit Jul 3, 2025
97d365f
fix passwordValidator function
avatarit Jul 3, 2025
35c9171
update the file
avatarit Jul 3, 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
11 changes: 0 additions & 11 deletions .vscode/extensions.json

This file was deleted.

21 changes: 15 additions & 6 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@

// Implement a function getAngleType
// Build up your function case by case, writing tests as you go
// The first test and case is written for you. The next case has a test, but no code.
// Execute this script in your terminal
// node 1-get-angle-type.js
//node 1-get-angle-type.js
// The assertion error will tell you what the expected output is
// Write the code to pass the test
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle === 90) return "Right angle";
if (angle > 0 && 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";
// If the angle is not in any of the above categories, we can return a default value
return "Unknown angle type";
// read to the end, complete line 36, then pass your test here
}

Expand Down Expand Up @@ -42,15 +49,17 @@ 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
const Reflex = getAngleType(200);
assertEquals(Reflex,"Reflex angle");
13 changes: 10 additions & 3 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator >= denominator)return false;

}

// here's our helper again
Expand All @@ -20,7 +22,6 @@ function assertEquals(actualOutput, targetOutput) {
}

// Acceptance criteria:

// Proper Fraction check:
// Input: numerator = 2, denominator = 3
// target output: true
Expand All @@ -40,14 +41,20 @@ assertEquals(improperFraction, false);
// 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
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(improperFraction,false);

// 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);
34 changes: 25 additions & 9 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// 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
Expand All @@ -8,20 +7,30 @@
// 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;
}
if (!card || typeof card !== "string") return "Invalid card format";
//extracting the rank of the card
const rank = card.slice(0, -1);

//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN.
if (rank === "A") return 11;
//For numerical cards, we return the number
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank);
//For face cards, we return 10
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10;
//If the card is invalid, we throw an error
else return("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}`
);
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
Expand All @@ -33,19 +42,26 @@ assertEquals(aceofSpades, 11);
// 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.
assertEquals(getCardValue("J♣"), 10);
assertEquals(getCardValue("Q♦"), 10);
assertEquals(getCardValue("K♠"), 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 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."
const Invalidcardrank = getCardValue("1♦");
assertEquals(Invalidcardrank,"Invalid card rank.");
16 changes: 8 additions & 8 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (angle > 0 && 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";
// If the angle is not in any of the above categories, we can return a default value
return "Unknown angle type";
// read to the end, complete line 36, then pass your test here
}






module.exports = getAngleType;


// Don't get bogged down in this detail
Expand Down
25 changes: 25 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,40 @@ 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 angles (less than 90°)", () => {
expect(getAngleType(45)).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 angles (between 90° and 180°)", () => {
expect(getAngleType(120)).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 angles (between 180° and 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});


4 changes: 4 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator === denominator)return false;
if (numerator > denominator)return false;
return false;

// add your completed function from key-implement here
}

Expand Down
15 changes: 15 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
const isProperFraction = require("./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", () => {
expect(isProperFraction(6, 3)).toEqual(false);
});

test("should return false for a negative improper fraction", () => {
expect(isProperFraction(-3, -4)).toEqual(false);
});

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for equal numerator and denominator", () => {
expect(isProperFraction(5,5)).toEqual(false);
});

18 changes: 15 additions & 3 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@

function getCardValue(card) {
// replace with your code from key-implement
return 11;
}
if (!card || typeof card !== "string") return "Invalid card format";
//extracting the rank of the card
const rank = card.slice(0, -1);

//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN.
if (rank === "A") return 11;
//For numerical cards, we return the number
else if (Number(rank) >= 2 && Number(rank) <= 10) return Number(rank);
//For face cards, we return 10
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10;
//If the card is invalid, we throw an error
else return("Invalid card rank.");
}

module.exports = getCardValue;
37 changes: 33 additions & 4 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
const getCardValue = require("./3-get-card-value");

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

// Case 2: Handle Number Cards (2-10):


test("should return the correct value for number cards (2-10)", () => {
expect(getCardValue("2♦")).toEqual(2);
expect(getCardValue("5♣")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
});

// Case 3: Handle Face Cards (J, Q, K):


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

// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:

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

// Case 5: Handle Invalid Cards:

test("should throw an error for invalid cards", () => {
expect(getCardValue("Z♦")).toEqual("Invalid card rank.");
expect(getCardValue("15♥")).toEqual("Invalid card rank.");
expect(getCardValue("X♣")).toEqual("Invalid card rank.");
});
4 changes: 3 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
//return 5

return stringOfCharacters.split(findCharacter).length - 1;
}

module.exports = countChar;
32 changes: 31 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// implement a function countChar that counts the number of times a character occurs in a string

// implement a function countChar that counts the number of times a character occurs in a string
const countChar = require("./count");
// Given a string str and a single character char to search for,
// When the countChar function is called with these inputs,
Expand All @@ -22,3 +23,32 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

test("should return 0 when the character is not found", () => {
const str = "hello";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should be case-sensitive", () => {
const str = "Millena";
const char = "m";
const count = countChar(str, char);
expect(count).toEqual(0);
});


test("should count spaces as characters", () => {
const str = "Millena Mesfin";
const char = " ";
const count = countChar(str, char);
expect(count).toEqual(1);
});

test("should return 0 for an empty string", () => {
const str = "";
const char = "m";
const count = countChar(str, char);
expect(count).toEqual(0);
});
Loading