Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
29f288e
Implemented condition to check if angle is less than 90
ike-agu Jun 19, 2025
bb789a2
added conditional statements and assertions to complete exercise 1-ge…
ike-agu Jun 19, 2025
de201cb
added test assertions to complete exercise 2-is-proper-fraction
ike-agu Jun 19, 2025
dbe53d3
Impleneted function to get card value for exercise 3-get-card-value.js
ike-agu Jun 24, 2025
9756c95
added completed getAngleType funtion from Key-implement exercise
ike-agu Jun 24, 2025
e1f86d2
Added tests for get angle type exercise
ike-agu Jun 24, 2025
2f478fd
added my isProperFraction function from key-implement
ike-agu Jun 24, 2025
f796929
I added tests is Proipoer Fraction exercise
ike-agu Jun 24, 2025
3fe535b
added codes from getCardValue function
ike-agu Jun 24, 2025
5b28aa1
added tests for get card value exercise
ike-agu Jun 24, 2025
a124d85
added completed getAngleType funtion from Key-implement exercise
ike-agu Jun 24, 2025
65fb383
added tests for getOrdinalNumber from 1 - 11
ike-agu Jun 24, 2025
a777952
added tests cases for repeat.test exercise
ike-agu Jun 25, 2025
0071b2f
Implemented credit card validator function
ike-agu Jun 26, 2025
1e9d34d
Added comments to answer questions regarding the function find and th…
ike-agu Jun 26, 2025
8d57ee1
implemented passwordValidator function
ike-agu Jul 3, 2025
2c3d18a
added test to check if password has uppercase or lowercase letter
ike-agu Jul 3, 2025
4dc0a9e
added test to check if password has atleast one number 0-9
ike-agu Jul 3, 2025
7cd8988
added test to check if password has atleast one non-aphanumeric symbols
ike-agu Jul 3, 2025
1f98cca
fixed test to check if password has already been used. Changed return…
ike-agu Jul 3, 2025
60897ed
Changed return message for password already been used to equals to f…
ike-agu Jul 3, 2025
9e62f36
Implemented get get ordinal number function
ike-agu Jul 3, 2025
9de4207
fixed test cases for get ordinal numbers function
ike-agu Jul 4, 2025
224044d
fixed test case password has atleast 5 characters
ike-agu Jul 4, 2025
1e0ea6c
Implemented count Character function
ike-agu Jul 4, 2025
79fcbe9
Implemented repeat function
ike-agu Jul 4, 2025
826f604
Implemented functionality to check the cards are not all the same digit
ike-agu Jul 5, 2025
24e0cbe
edit the file in line 4
ike-agu Jul 5, 2025
bee5248
added checks for angle less than or equals to zero and the ones great…
ike-agu Jul 5, 2025
8947ab5
implemented isProper fraction to ensure denominator is not zero. I al…
ike-agu Jul 6, 2025
155ed1e
updated get-card-value.js to ensure only standard card ranks are acce…
ike-agu Jul 6, 2025
c619fd9
updated get-card-value.js to throw new Error(Invalid Card rank).
ike-agu Jul 6, 2025
03edb9b
implemented is proper fraction to handle negative values and zero den…
ike-agu Jul 6, 2025
30550bc
fixed function to handle zero denominators and negative numbers
ike-agu Jul 6, 2025
2b0b26f
grouped test cases under the category append 'th' to numbers ending …
ike-agu Jul 6, 2025
4180eb3
updated get-card-value.js to throw new Error(Invalid Card rank).
ike-agu Jul 6, 2025
32ab610
I group test cases for numbers ending in 1,2 and 3 to improve coverag…
ike-agu Jul 6, 2025
586fbd2
Implemented throw new error message
ike-agu Jul 6, 2025
6cd07d3
fixed the test case to throw error when count is negative
ike-agu Jul 6, 2025
ffd50fa
I added test cases to to return false when the password is invalid e.…
ike-agu Jul 7, 2025
9eff376
I added = sign to check if sum is <= to 16
ike-agu Jul 7, 2025
dab298c
added lowercase t
ike-agu Jul 7, 2025
ec0084a
fixed function to throw new error when denominator is zero
ike-agu Jul 7, 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
22 changes: 19 additions & 3 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if(angle <= 0 || angle >= 360) return "Invalid angle";
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 > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if(angle > 180 && angle < 360) return "Reflex angle";
}

console.log(getAngleType(-2));
// 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) {
Expand Down Expand Up @@ -41,16 +47,26 @@ assertEquals(acute, "Acute angle");

// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// if(angle > 90 && angle is < 180) return "Obtuse angle"
// 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

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(360)
assertEquals(reflex, "Reflex angle");

const fromZeroBelow = getAngleType(-5)
assertEquals(fromZeroBelow, "Invalid angle")

const threeSixtyAndAbove = getAngleType(360);
assertEquals(threeSixtyAndAbove, "Invalid angle");
11 changes: 10 additions & 1 deletion 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,14 @@
// 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 "Denominator cannot be zero";
}
if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +48,15 @@ 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?
29 changes: 28 additions & 1 deletion Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@
// 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.slice(0,-1); // this line removes the emojis

if (rank === "A") {
return 11;
} else if (+rank >= 2 && +rank <= 10) {
return +rank;
} else if (rank === "J" || rank === "Q" || rank === "K"){
return 10;
} else {
return "Invalid Card rank.";
}
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -34,12 +45,26 @@ 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 rankTen = getCardValue("10♥");
assertEquals(rankTen, 10);

const cardK = getCardValue("K♠");
assertEquals(cardK, 10);

const cardJ = getCardValue("J♣");
assertEquals(cardJ, 10);

const cardQ = getCardValue("Q♦");
assertEquals(cardQ, 10)


// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
Expand All @@ -49,3 +74,5 @@ 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."
const invalidCards = getCardValue("");
assertEquals(invalidCards, "Invalid Card rank.");
9 changes: 6 additions & 3 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

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";
}


Expand All @@ -13,6 +16,6 @@ function getAngleType(angle) {

// 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;
14 changes: 14 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 @@ -11,14 +11,28 @@ test("should identify right angle (90°)", () => {
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"

test("should identify Acute angle when Angle is less than 90°", ()=>{
expect(getAngleType(80)).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 when Angle is greater than 90° and less thank 180°", () => {
expect(getAngleType(101)).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 when Angle is 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 angle when Angle is greater than 180° and less than 360°", () => {
expect(getAngleType(202)).toEqual("Reflex angle");
});
15 changes: 13 additions & 2 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;

// add your completed function from key-implement here
if(denominator === 0){
throw new Error("Denominator cannot be zero")
}
if( Math.abs(numerator) < Math.abs(denominator)){
return true;
}else{
return false;
}
}

module.exports = isProperFraction;
console.log(isProperFraction(-3, 0));

// console.log(isProperFraction(-4, 6));
module.exports = isProperFraction;
11 changes: 9 additions & 2 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,14 @@ 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 when numerator is Equal to denominator ", () => {
expect(isProperFraction(3,3)).toEqual(false);
});
17 changes: 15 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,18 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
let rank = card.slice(0, -1); // this line removes the emojis

const rangeTwoToTenArray = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];//

if (rank === "A") {
return 11;
} else if (rangeTwoToTenArray.includes(rank)) {
return parseInt(rank);
} else if (rank === "J" || rank === "Q" || rank === "K") {
return 10;
} else {
throw new Error("Invalid Card rank.");
}
}
module.exports = getCardValue;

module.exports = getCardValue;
16 changes: 14 additions & 2 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,23 @@
const getCardValue = require("./3-get-card-value");

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

// Case 2: Handle Number Cards (2-10):
test("Should return rank number between 2 and 10",()=>{
expect(getCardValue("5♥")).toEqual(5);
});

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

// Case 4: Handle Ace (A):
// Case 5: Handle Invalid Cards:
test("should throw an error indicating Invalid card rank.", () => {
expect(() => getCardValue("")).toThrow("Invalid Card rank.");
});
13 changes: 10 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
function countChar(strOfCahracters, findcharacter) {
let count = 0;
for (let i = 0; i < strOfCahracters.length; i++) {
if (strOfCahracters[i] === findcharacter) {
count++;
}
}
return count;
}

module.exports = countChar;
// console.log(countChar("aaaaa", "a"));
module.exports = countChar;
7 changes: 7 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ 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 identify no occurrences of character", () => {
const str1 = 'AAAAA'
const char1 = 'a'
const count = countChar(str1, char1)
expect(count).toEqual(0);
});
21 changes: 19 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,22 @@
function getOrdinalNumber(num) {
return "1st";
let lastNumber = num % 10; // Using the modulo operator to get the last digit of the number.
let lastTwoNumbers = num % 100; //Using the modulo operator to get the last two digits of the number.

if (lastTwoNumbers === 11 || lastTwoNumbers === 12 || lastTwoNumbers === 13) {
return num + "th";
}

if (lastNumber === 1) {
return num + "st";
} else if (lastNumber === 2) {
return num + "nd";
} else if (lastNumber === 3) {
return num + "rd";
} else {
return num + "th";
}
}

module.exports = getOrdinalNumber;
console.log(getOrdinalNumber(3));

module.exports = getOrdinalNumber;
26 changes: 23 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,26 @@ 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("Should append 'st' to numbers ending in 1, except those ending in 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(101)).toEqual("101st");
});

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

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

test("Should append 'th' to numbers ending in 11, 12, 13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
11 changes: 8 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if (count < 0) {
throw new Error("Negative numbers are not valid!");
} else {
return str.repeat(count);
}
}

module.exports = repeat;
// console.log(repeat("", -1));
module.exports = repeat;
Loading