Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65fe894
Answered comment for count update in exercise -1
ahmadehsas Jun 16, 2025
532fd66
Implement getAngleType with complete test coverage and improved test …
ahmadehsas Jul 7, 2025
0cba6bb
Completed the rest the tests and cases
ahmadehsas Jul 7, 2025
8d6eb95
Implement getCardValue function with test cases for number, face, ace…
ahmadehsas Jul 9, 2025
2479c4f
Implement getAngleType function to classify angle types
ahmadehsas Jul 9, 2025
3fafedf
Add test cases for angle types and update Sprint-1 readme
ahmadehsas Jul 10, 2025
7a5fe08
Added function(isProperFraction)
ahmadehsas Jul 10, 2025
68f5551
Identified Improper, Negative and equal fractions.
ahmadehsas Jul 10, 2025
5dd3b88
Rewrote the Card value function and tests
ahmadehsas Jul 10, 2025
62ef41d
completed the countChar function with a short clear description and t…
ahmadehsas Jul 10, 2025
1443cbf
completed the No occurrences Scenario test
ahmadehsas Jul 10, 2025
1e2318b
completed the function getOrdinalNumber.
ahmadehsas Jul 11, 2025
edea881
the test is passed for get-ordinal-number.js
ahmadehsas Jul 11, 2025
dbf4e92
Implemented the function and the test was passed
ahmadehsas Jul 11, 2025
fad2100
Edited incorrect test cases and fixed logic to ensure all tests pass …
ahmadehsas Jul 12, 2025
1154f89
Add else condition to simplify my code.
ahmadehsas Jul 20, 2025
047df5d
Add jest .toThrow method for checking if the function can throw the e…
ahmadehsas Jul 20, 2025
ba0f73e
implement the the function getOrdinalNumber that works for any vali p…
ahmadehsas Jul 20, 2025
5aeb5c0
prepare tests for all valid integers.
ahmadehsas Jul 20, 2025
550f44d
combine tests for number cards and Face cards.
ahmadehsas Jul 21, 2025
e76a59c
update the function to hundle invalid input.
ahmadehsas Jul 21, 2025
3415822
update the test code to hundle expected cases.
ahmadehsas Jul 21, 2025
bf5f7f8
Match the error message in toThrow() matcher function.
ahmadehsas Jul 21, 2025
4f1e86a
Delete Sprint-1/1-key-exercises/1-count.js
ahmadehsas Jul 21, 2025
e5699a5
Delete Sprint-1/readme.md
ahmadehsas Jul 21, 2025
63d4861
Restored deleted files from Sprint-1 to fix accidental changes
ahmadehsas Jul 23, 2025
e749f57
update the tests for all valid integers.
ahmadehsas Jul 23, 2025
d34b464
Add test code to cover all valid integers.
ahmadehsas Jul 25, 2025
fb90283
Add input validation to ensure the function only accept valid card va…
ahmadehsas Jul 25, 2025
8b3fd7a
Check if the Number(rank) works instead of parseint(rank, 10).
ahmadehsas Oct 19, 2025
b1e528f
deleted sprint-1 subforlder from sprint-3.
ahmadehsas Oct 28, 2025
e956cdc
Some folders have been renamed.
ahmadehsas Oct 29, 2025
c57fbd0
reverted files from sprint-1 to sprint-3.
ahmadehsas Oct 29, 2025
7490201
Merge branch 'main' into coursework/sprint-3
ahmadehsas Oct 29, 2025
154071d
Resolved merge conflicts with main updated Sprint-3 structure.
ahmadehsas Oct 30, 2025
30dfbd8
Transferred all of my changes to the updated foldersand removed all o…
ahmadehsas Oct 30, 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
Copy link
Contributor

Choose a reason for hiding this comment

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

image

The subfolder containing these two files were moved from its original folder.

File renamed without changes.
4 changes: 2 additions & 2 deletions Sprint-1/readme.md → Sprint-1/Sprint-1/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This README will guide you through the different sections for this week.

## 1 Exercises

In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.
In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation.

https://developer.mozilla.org/en-US/docs/Web/JavaScript

Expand All @@ -28,7 +28,7 @@ You must use documentation to make sense of anything unfamiliar - learning how t

You can also use `console.log` to check the value of different variables in the code.

https://developer.mozilla.org/en-US/docs/Web/JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript

## 4 Explore - Stretch 💪

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
// 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 "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";

// read to the end, complete line 36, then pass your test here

if (angle === 90) {
return "Right angle";
}
Comment on lines +12 to 22
Copy link
Contributor

Choose a reason for hiding this comment

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

You have some redundant code here.

// 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 @@ -50,14 +60,19 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse, "Obtuse angle");
// ====> 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
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,14 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (Math.abs(numerator) < denominator) return true; // This version of code works correctly for proper and negative fractions.
if (Math.abs(numerator) >= Math.abs(denominator)) return false;
if (Math.abs(numerator) === Math.abs(denominator)) return false;

if (numerator < denominator) {
return true;
}
Comment on lines +11 to 17
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What do you expect from isProperFraction(-2, -3)?

  • Some of the code is redundant.


}

// The line below allows us to load the isProperFraction function into tests in other files.
Expand Down Expand Up @@ -46,14 +51,18 @@ 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); // assertion for negative fraction.

// 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); // assertion for equal numerator and denominator.
// ====> complete with your assertion

// Stretch:
// What other scenarios could you test for?
console.log(isProperFraction(5, 2));
console.log(isProperFraction(-4, 7));
console.log(isProperFraction(-3, 3));
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,35 @@
// 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); // get the rank (before the suit symbol)

if (!isNaN(rank)) {
return Number(rank); // Number card
}
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", "9e1" or "0002"

Do you want to recognize these string values as valid ranks?


if (rank === "J" || rank === "Q" || rank === "K") {
return 10; // Face cards
}

if (rank === "A") return 11; // Ace

// Anything else is invalid
throw new Error("Invalid card rank");
}

// if the rank is not a number or a face card, throw an error(invalid card rank).

// if (rank === "x") {
// return 11;
// }



// 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
Expand All @@ -39,13 +59,23 @@ 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);

const tenofDiamonds = getCardValue("10♦");
assertEquals(tenofDiamonds, 10);

// 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 jackofClubs = getCardValue("J♣");
assertEquals(jackofClubs, 10);

const queenofHearts = getCardValue("Q♥");
assertEquals(queenofHearts, 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,
Expand All @@ -55,3 +85,8 @@ const fiveofHearts = getCardValue("5♥");
// 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♠");
// } catch (error) {
// console.log("Caught error:", error.message); // Should say "Invalid card rank"
// }
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,33 @@ 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 2: identify Acute Angles, When the angle is less than 90 degrees, than 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"
test("should identify obtuse angle (> 90° and < 180°)", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
});
// Case 3: identify Obtuse Angles, When the angle is greater than 90 degrees and less than 180 degrees, than the function should return "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 4: identify Straight Angles, When the angle is exactly 180 degrees, than the function should return "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");
});
// Case 5: identify Reflex Angles, When the angle is greater than 180 degrees and less than 360 degrees, the function should return "Reflex Angle".

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:
est("should return false for improper fractions", () => {
const improperFraction = isProperFraction(5, 2);
expect(improperFraction).toEqual(false);
});

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

Comment on lines +16 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

Not all negative fractions are proper fractions. For example, -5/2.

If you allow negative denominator, then you could also test isProperFraction(4, -7), isProperFraction(-4, -7), isProperFraction(-7, 4), isProperFraction(-7, -4), isProperFraction(7, -4).


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

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,58 @@
// We will use the same function, but write tests for it using Jest in this file.
const getCardValue = require("../implement/3-get-card-value");


// Case 4: Handle Ace (A):
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 correct values for number cards", () => {
expect(getCardValue("5♥")).toEqual(5);
expect(getCardValue("10♦")).toEqual(10);
});


// Case 3: Handle Face Cards (J, Q, K):
// Case 4: Handle Ace (A):
test("should return for face cards J, Q, K", () => {
expect(getCardValue("J♣")).toEqual(10);
expect(getCardValue("Q♦")).toEqual(10);
expect(getCardValue("K♠")).toEqual(10);
});



// Case 5: Handle Invalid Cards:
test("throws an error or invalid card", () => {
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
});

test("should throw error for malformed numeric input", () => {
expect(() => getCardValue("2.9999♠")).toThrow("Invalid card rank");
});

test("should throw error for repeated characters in rank", () => {
expect(() => getCardValue("3AAAA♠")).toThrow("Invalid card rank");
});

test("should throw error for number beyond valid range", () => {
expect(() => getCardValue("11♠")).toThrow("Invalid card rank");
});

test("should throw error for missing suit", () => {
expect(() => getCardValue("Q")).toThrow("Invalid card rank");
});

test("should throw error for non-string input", () => {
expect(() => getCardValue(5)).toThrow("Card must be a string");
});

Comment on lines +29 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can you current implementation pass all these tests?

  • Why specifically test "repeated characters" in rank? What's so special about this particular string pattern?

  • "2.9999" is not really a malformed numeric value.

  • The function is not expected to check the suit character. Including a test for missing suit might send the wrong message to the person implementing the function.

// try {
// getCardValue("Z♠");
//} catch (error) {
// console.log("Caught error:", error.message);
//}


13 changes: 12 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0; // start a count with 0
for (let char of stringOfCharacters) {
// repeat for each character in the string
if (char === findCharacter) {
// check if the character matches the one we are looking for.
count++; // if it does increase the count by 1.
}
}

return count;

}
console.log(countChar("aAaAaAaAa", "a")); // example usage should return 5.

module.exports = countChar;
9 changes: 9 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ 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 character does not exist in the string", () => {
const str = "aaaaa";
const char = "b";
const result = countChar(str, char);
expect(result).toEqual(0);
});
// the above test cases are for the countChar function that counts the number of times a character occurs in a string.
// this function should return 0 because the character `b` does not exist in the string "aaaaa".
17 changes: 16 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
function getOrdinalNumber(num) {
return "1st";
let ord = "th";

if (n % 10 == 1 && n % 100 != 11) {
ord = "st";
} else if (n % 10 == 2 && n % 100 != 12) {
ord = "nd";
} else if (n % 10 == 3 && n % 100 != 13) {
ord = "rd";
}

return n + ord;
}
console.log(getOrdinalNumber(1)); // The output should be "1st"

// in this function, we got the ordinal number for 1.
// we used a simple if statement to check if the number is 1 and return "1st".


module.exports = getOrdinalNumber;
42 changes: 41 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ const getOrdinalNumber = require("./get-ordinal-number");
// When the number is 1,
// Then the function should return "1st"

test("should return '1st' for 1", () => {

test("append 'st' to numbers ending in 1, except those ending in 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(121)).toEqual("121st");
});

test("appends 'nd' to numbers ending in 2, except those ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
});

test("appends 'rd' to numbers ending in 3, except those ending in 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
});

test("appends 'th' to numbers ending in 11, 12, or 13 and all others not ending in 1, 2, or 3", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");

//general `th` cases

expect(getOrdinalNumber(0)).toEqual("0th");
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(10)).toEqual("10th");
expect(getOrdinalNumber(24)).toEqual("24th");
expect(getOrdinalNumber(100)).toEqual("100th");
expect(getOrdinalNumber(104)).toEqual("104th");
});

test("handles edge cases for higher numbers", () => {
expect(getOrdinalNumber(1011)).toEqual("1011th");
expect(getOrdinalNumber(1012)).toEqual("1012th");
expect(getOrdinalNumber(1013)).toEqual("1013th");
expect(getOrdinalNumber(1021)).toEqual("1021st");
expect(getOrdinalNumber(1022)).toEqual("1022nd");
expect(getOrdinalNumber(1023)).toEqual("1023rd");
});
8 changes: 7 additions & 1 deletion Sprint-3/2-practice-tdd/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function repeat() {
return "hellohellohello";
if (times < 0) {
throw new Error("Times must be a non-negative integer");
}
return word.repeat(times);
}
console.log(repeat("hello", 3)); // The output should be "hellohellohello"



module.exports = repeat;
Loading