Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
40adc65
Create sprint-1
sheida-shab Jun 7, 2025
c61fb0c
implementing function get angel
sheida-shab Jun 14, 2025
71fa8a2
writing and passing test cases for angels
sheida-shab Jun 14, 2025
89c7448
implementing function for proper fraction
sheida-shab Jun 14, 2025
1082edb
writing and passing tests for proper fraction
sheida-shab Jun 14, 2025
d9a58aa
implementing function for card values
sheida-shab Jun 14, 2025
44ed00b
writing and passing test cases for function card values
sheida-shab Jun 14, 2025
e8a7465
implementig and testing function with assert
sheida-shab Jun 14, 2025
50a07af
Implement and assert function isProperFraction
sheida-shab Jun 16, 2025
d7b198c
implement and assert function getCardValue
sheida-shab Jun 16, 2025
ce6b980
more assertion and error catch
sheida-shab Jun 16, 2025
ab10b0b
update and improve function and test
sheida-shab Jun 16, 2025
25e466c
updatin and catch error
sheida-shab Jun 16, 2025
26d4e68
update function
sheida-shab Jun 16, 2025
b3c1079
implement and test function countChar
sheida-shab Jun 16, 2025
0cd41c0
testing and implementing getOrdinalNumber function
sheida-shab Jun 16, 2025
d33ce93
Implement & test function repeat except error handling
sheida-shab Jun 16, 2025
3084993
Implement function repeat and write test cases
sheida-shab Jun 16, 2025
7f28d1a
play computer find function
sheida-shab Jun 16, 2025
8a271db
write program Password Validation and test cases
sheida-shab Jun 16, 2025
91de44d
Add more test case
sheida-shab Jun 18, 2025
1c6712c
add some comments
sheida-shab Jun 18, 2025
9f7a062
Add abs function
sheida-shab Jun 27, 2025
8bb9053
change variable names
sheida-shab Jun 28, 2025
e1a7f32
check ["♠", "♥", "♦", "♣"] only once
sheida-shab Jun 29, 2025
fedcfaf
card’s rank matches exactly allowed numbers
sheida-shab Jun 29, 2025
f9c3394
fix the typo mistake
sheida-shab Jun 29, 2025
38458ec
improve functions and use suggestions for better code
sheida-shab Jun 29, 2025
e9c214a
delete folder coursework/sprin1
sheida-shab Jun 29, 2025
7800bb0
simplify the code
sheida-shab Jun 29, 2025
68cf386
improve the function checking
sheida-shab Jun 29, 2025
c4261ec
manage 111 ordinal number
sheida-shab Jun 29, 2025
ea54b62
using else and else if
sheida-shab Jun 29, 2025
2f429e6
grouping the tests in to 5 group
sheida-shab Jun 29, 2025
652e6b6
change the answer of d question
sheida-shab Jun 29, 2025
6055567
solving the error message
sheida-shab Jun 29, 2025
fcac4b6
improve the indentation
sheida-shab Jun 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.DS_Store
.vscode
**/.DS_Store
**/.DS_Store
16 changes: 12 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 @@ -8,8 +8,12 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle < 90) return "Acute angle";
if (angle === 180) return "Straight angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle > 180) return "Reflex angle";
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -43,14 +47,18 @@ 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(220);
assertEquals(reflex, "Reflex angle");
15 changes: 12 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 @@ -8,7 +8,9 @@
// 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) < Math.abs(denominator) && Math.abs(numerator) != 0
);
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +43,20 @@ assertEquals(improperFraction, false);
// 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(equalFraction, false);
// Stretch:
// What other scenarios could you test for?
//undefined fraction : denominator equal to 0
const undefinedFrction = isProperFraction(3, 0);
assertEquals(undefinedFrction, false);

//Zero fraction : numerator is equal to 0
const zeroFrction = isProperFraction(0, 5);
assertEquals(zeroFrction, false);
40 changes: 32 additions & 8 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,36 @@
// 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) {
if (rank === "A") return 11;
let rank = card[0];

if (["♠", "♥", "♦", "♣"].includes(card.slice(-1))){
if (card.length > 2) {
rank = card.slice(0, card.length - 1);
}
if (rank === "A") return 11;
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank.toString()) )
return rank;
if (["J", "Q", "K"].includes(rank))
return 10;
}

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}`
);
try {
console.assert(
actualOutput === targetOutput,
`Expected ${actualOutput} to equal ${targetOutput}`
);
} catch (Error) {
console.error("error!!"), Error.message;
}
}
// Acceptance criteria:

Expand All @@ -33,19 +51,25 @@ 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♥");
assertEquals(parseInt(fiveofHearts), 5);
// ====> write your test here, and then add a line to pass the test in the function above

const tenCards = getCardValue("10♥");
assertEquals(parseInt(tenCards), 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 faceCards = getCardValue("J♥");
assertEquals(parseInt(faceCards), 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 aceCards = getCardValue("A♥");
assertEquals(aceCards, 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 invalidCards = getCardValue("223");
assertEquals(invalidCards, 0);
17 changes: 7 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,15 @@
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) return "Reflex angle";

// replace with your completed function from key-implement
}








// 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 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;
15 changes: 13 additions & 2 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,26 @@ 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 less than (90°)", () => {
expect(getAngleType(89.99)).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 greater than (90°) and less than (180°)", () => {
expect(getAngleType(120)).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"
// Then the function should return "node 1 angle"
test("should identify node 1 angle greater than (180°) and less than (360°)", () => {
expect(getAngleType(220)).toEqual("Reflex angle");
});
6 changes: 3 additions & 3 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (Math.abs(numerator) < Math.abs(denominator)) return true;
return false;
}

module.exports = isProperFraction;
module.exports = isProperFraction;
12 changes: 12 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 @@ -6,6 +6,18 @@ test("should return true for a proper fraction", () => {

// Case 2: Identify Improper Fractions:

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

// Case 3: Identify Negative Fractions:

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

// Case 4: Identify Equal Numerator and Denominator:
test("should return false for Equal Numerator and Denominator", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
19 changes: 16 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,18 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
// replace with your code from key-implement
let rank = card[0];

if (["♠", "♥", "♦", "♣"].includes(card.slice(-1))){
if (card.length > 2) {
rank = card.slice(0, card.length - 1);
}

if (rank === "A") return 11;
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank))
return parseInt(rank);
if ( ["J", "Q", "K"].includes(rank) )
return 10;
}
module.exports = getCardValue;
throw new Error("Invalid card rank.");
}
module.exports = getCardValue;
23 changes: 20 additions & 3 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,28 @@
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 number of the card for 2♥", () => {
const numberCards = getCardValue("2♥");
expect(numberCards).toEqual(2);
});

// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for J♣", () => {
const faceCards = getCardValue("J♣");
expect(faceCards).toEqual(10);
});

// Case 4: Handle Ace (A):
test("should return 11 for A♥", () => {
const aceCards = getCardValue("A♥");
expect(aceCards).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("throws error on invalid card", () => {
expect(() => getCardValue("223")).toThrow(Error.message);
});
10 changes: 8 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0;
for (let i = 0; i <= stringOfCharacters.length - 1; i++) {
if (stringOfCharacters[i] === findCharacter) {
count++;
}
}
return count;
}

module.exports = countChar;
module.exports = countChar;
19 changes: 18 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ test("should count multiple occurrences of a character", () => {
const count = countChar(str, char);
expect(count).toEqual(5);
});

test("should count multiple occurrences of a character", () => {
const str = "absfka";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(2);
});
// Scenario: No Occurrences
// Given the input string str,
// 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 count 0 for no occurrences of a character", () => {
const str = "absfka";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});
test("should count 0 for no occurrences of a character & case sensitive ", () => {
const str = "Zbsfka";
const char = "z";
const count = countChar(str, char);
expect(count).toEqual(0);
});
18 changes: 16 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function getOrdinalNumber(num) {
return "1st";
let lastDigit = num.toString().slice(-1);
let last2Digit = num.toString().slice(-2);
let numToString = num.toString();

if (["11", "12", "13"].includes(last2Digit)) {
return numToString + "th";
} else if (lastDigit === "1") {
return numToString + "st";
} else if (lastDigit === "2") {
return numToString + "nd";
} else if (lastDigit === "3") {
return numToString + "rd";
} else {
return numToString + "th";
}
}

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

test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});
test("'st' for numbers ending in 1 but not ending in 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
});

test("'nd' for numbers ending in 2 but not ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(32)).toEqual("32nd");
});

test("'rd' for numbers ending in 3 but not ending in 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});

test("'th' for numbers ending in 11 , 12 and 13 ", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});

test("'th' for any other numbers ", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(24)).toEqual("24th");
expect(getOrdinalNumber(100)).toEqual("100th");
expect(getOrdinalNumber(10)).toEqual("10th");
expect(getOrdinalNumber(111)).toEqual("111th");
});



Loading