Skip to content
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9167e67
update 1-key-implement/1-get-angle-type.js
iteddy16 Jun 13, 2025
f9da79b
1-key-implement/2-is-proper-fractions.js
iteddy16 Jun 13, 2025
da2169b
1-key-implement/3-get-card-values.js
iteddy16 Jun 13, 2025
6894bd8
update sprint-1 1-key-exercise/1-count.js
iteddy16 Jun 14, 2025
cb1730c
Sprint-3/1-key-implement/1-get-angle-type.js
iteddy16 Jun 23, 2025
55d8c9f
Updated Sprint-3\2\1-get-angle-type.js
iteddy16 Jun 24, 2025
3a6390e
Updated Sprint-3\2-mandatory-rewrite\1-get-angle-type and test.js
iteddy16 Jun 24, 2025
796a8cf
update sprint-3\2\2-is-proper-fraction.js and test
iteddy16 Jun 24, 2025
b014b98
update sprint-3\2\3-get-card-values.js and test.js
iteddy16 Jun 24, 2025
7e10cb8
update sprint-3\3\count.js and count.test.js
iteddy16 Jun 24, 2025
0771e60
update sprint-3\3\get-ordinal-number.js and test.js
iteddy16 Jun 24, 2025
c8ed1bb
update Sprint-3\3\repeat.js and repeat.test.js
iteddy16 Jun 24, 2025
e9ab61e
add card-validator.js for credit card validation functionality sprint…
iteddy16 Jun 24, 2025
04360b4
update sprint-3\4\find.js
iteddy16 Jun 24, 2025
ce4fb74
update sprint-3\4\password-validator.js
iteddy16 Jun 24, 2025
63dda1e
Updates fro sprint-3/1-get-angle-type, 2-is-proper-fraction, and 3-ge…
iteddy16 Jul 9, 2025
ab8f199
update the getCardValue function
iteddy16 Jul 9, 2025
d96efd6
updated sprint-3/1-get-angle-type
iteddy16 Jul 9, 2025
1fc4d18
updates for get angle and get card
iteddy16 Jul 9, 2025
3ea90b1
update sprint-3/3-mandatory practice/count and count.test.js
iteddy16 Jul 9, 2025
76a9808
updates sprint-3/get-ordinal-numbers.js
iteddy16 Jul 9, 2025
5ed0d66
update sprint-3/find.js
iteddy16 Jul 9, 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
1 change: 1 addition & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ count = count + 1;

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing
// Line 3 is updating the value of the count variable by adding 1 to its current value. The = operator is used for assignment, it assigns values to variables. In this case, it takes the current value of count (which is 0) and adds 1 to it, resulting in a new value of 1 for count.
71 changes: 65 additions & 6 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,25 @@
// 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";
// read to the end, complete line 36, then pass your test here

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( angle < 0 || angle > 360)
return "Invalid Angle"; // This handles angles outside the 0-360 range
if(angle === 0 || angle === 360)

Choose a reason for hiding this comment

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

This function looks good.

Could you use the conditional angle <= 0 || angle >= 360 to decide whether the parameter is an "Invalid Angle"?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it works for < 0 and exact 0 and >360 and exact 360 returns invalid.
code2

return "Invalid Angle"; // This handles angles outside the 0-360 range
// you can add more cases here as needed
// but make sure to write tests for each case first
// and then implement the code to pass the test
// this will help you build your function step by step
// and ensure that each case is handled correctly
// you can also add more tests to cover edge cases
// for example, what happens if the angle is negative or greater than 360?
// you can also add tests for angles that are not whole numbers
}

// we're going to use this helper function to make our assertions easier to read
Expand All @@ -31,26 +48,68 @@ function assertEquals(actualOutput, targetOutput) {
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"
const right = getAngleType(90);
assertEquals(right, "Right angle");
assertEquals(right, "Right Angle");

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
const acute = getAngleType(45);
assertEquals(acute, "Acute angle");
const acute = getAngleType(89.9);
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);
const obtuse = getAngleType(90.5);
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");

// Case 6: Handle Invalid Angles:
// When the angle is less than 0 or greater than 360 degrees,
// Then the function should return "Invalid angle"
// ====> write your test here, and then add a line to pass the test in the function above
const invalid = getAngleType(361);
assertEquals(invalid, "Invalid Angle");

// Case 7: Handle Angles Exactly at 0:
// When the angle is exactly 0 degrees,
// Then the function should return "Invalid angle"
const zeroAngle = getAngleType(0);
assertEquals(zeroAngle, "Invalid Angle");

// Case 11: Handle Angles Exactly at 360:
// When the angle is exactly 360 degrees,
// Then the function should return "Invalid angle"
const fullCircle = getAngleType(360);
assertEquals(fullCircle, "Invalid Angle");


console.log(right);
console.log(acute);
console.log(obtuse);
console.log(straight);
console.log(reflex);
console.log(invalid);
console.log(zeroAngle);
console.log(fullCircle);
// If all assertions pass, the function is working correctly for the given cases
console.log("All tests passed!");






14 changes: 13 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,15 @@
// 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 (numerator < denominator) return true;
return false;
// Note: This function currently does not handle cases where the denominator is zero.
// If you want to handle that case, you can add a check for it.
// For example, you could add a case that returns false if the denominator is zero.
// If you want to handle negative fractions, you can also add a case for that.
// If you want to handle fractions where the numerator is equal to the denominator,
// you can also add a case for that.
// If you want to handle fractions that are not numbers, you can also add a case for that.

Choose a reason for hiding this comment

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

I see that you have added comments for handling edge cases for this function, seems like your requirements are well defined.

Perhaps this would be a good stretch for you to introduce logic for handling the denominator being zero.

How would you handle the situation where the numerator is -4 & the denominator is 3?

Copy link
Author

Choose a reason for hiding this comment

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

I added the zero denominator to throw an error, and for this logic (-4, 3) it's handled by ' if (numerator < denominator) return true;'

Choose a reason for hiding this comment

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

Thank you for adding that check to make sure the denominator is non-zero.

}

// here's our helper again
Expand Down Expand Up @@ -41,13 +49,17 @@ 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?

console.log(isProperFraction(3, 3));
66 changes: 54 additions & 12 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,7 @@
// 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 (rank === "A") return 11;
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -25,27 +25,69 @@ function assertEquals(actualOutput, targetOutput) {
// 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);
const ace_of_Spades = getCardValue("A♠");

Choose a reason for hiding this comment

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

In Javascript it is common to use the camel case naming convention, aceOfSpades.

In python it is common to use the snake case naming convention for variables e.g. ace_of_spades.

Copy link
Author

Choose a reason for hiding this comment

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

I have updated all to the correct form.
code4

assertEquals(ace_of_Spades, 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

// 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.

// 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.
// Handle Jack (J):
// Given a card with a rank of "J",
// When the function is called with a Jack,
// Then it should return 10 points, as Jacks are worth 10 points in blackjack.
const jack_of_Diamonds = getCardValue("J♦");
assertEquals(jack_of_Diamonds, 10);

// Handle Queen (Q):
// Given a card with a rank of "Q",
// When the function is called with a Queen,
// Then it should return 10 points, as Queens are worth 10 points in blackjack.
const queen_of_Hearts = getCardValue("Q♥");
assertEquals(queen_of_Hearts, 10);

// Handle King (K):
// Given a card with a rank of "K",
// When the function is called with a King,
// Then it should return 10 points, as Kings are worth 10 points in blackjack.
const king_of_Clubs = getCardValue("K♣");
assertEquals(king_of_Clubs, 10);

// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "10",
// 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, "10" should return 10).
const two_of_Spades = getCardValue("2♠");
assertEquals(two_of_Spades, 2);
const three_of_Hearts = getCardValue("3♥");
assertEquals(three_of_Hearts, 3);
const four_of_Diamonds = getCardValue("4♦");
assertEquals(four_of_Diamonds, 4);
const five_of_Hearts = getCardValue("5♥");
assertEquals(five_of_Hearts, 5);
const six_of_Clubs = getCardValue("6♣");
assertEquals(six_of_Clubs, 6);
const seven_of_Spades = getCardValue("7♠");
assertEquals(seven_of_Spades, 7);
const eight_of_Hearts = getCardValue("8♥");
assertEquals(eight_of_Hearts, 8);
const nine_of_Diamonds = getCardValue("9♦");
assertEquals(nine_of_Diamonds, 9);

// 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."
function getCardValue(card) {

Choose a reason for hiding this comment

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

This function is implemented well.

Replacing the getCardValue function at the top of this file with this one would be good.

Copy link
Author

Choose a reason for hiding this comment

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

I replaced the above getCardValue function.

const rank = card.slice(0, -1); // Extract the rank part of the card string
if (rank === "A") return 11; // Ace is worth 11 points
if (["J", "Q", "K"].includes(rank)) return 10; // Face cards are worth 10 points
const numericRank = parseInt(rank, 10); // Convert rank to a number
if (numericRank >= 2 && numericRank <= 10) return numericRank; // Number cards return their value
throw new Error("Invalid card rank"); // Throw an error for invalid ranks
}

console.log(getCardValue("A♠")); // 11
16 changes: 15 additions & 1 deletion Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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";
} else if (angle === 90) {
return "Right angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
}else if (angle > 180 && angle < 360) {

Choose a reason for hiding this comment

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

This function looks good and covers the requirements. Nice job.

The two checks for angle > 90 and angle > 180 are not necessary.

Copy link
Author

Choose a reason for hiding this comment

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

I updated the function to address all the comments to look like this, and I tested it for all possible outputs, and it works.
code5

Choose a reason for hiding this comment

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

This satisfies the criteria.

return "Reflex angle";
}
else {
return "Invalid angle";
}

}


console.log(getAngleType(-90)); // Right angle

Choose a reason for hiding this comment

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

Does the comment match the output for this statement?

Copy link
Author

Choose a reason for hiding this comment

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

I updated the function, and here is the output:
Screenshot 2025-07-09 at 19 15 36




Expand Down
25 changes: 24 additions & 1 deletion Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
const getAngleType = require("./1-get-angle-type");
const getAngleType = require("./1-get-angle-type");

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"
test("should identify acute angle (<90°)", () => {
expect(getAngleType(45)).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 (>90° and <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"
test("should identify reflex angle (>180° and <360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
});
// Case 6: Handle Invalid Angles:
// When the angle is less than 0 degrees or greater than or equal to 360 degrees,
// Then the function should return "Invalid angle"
test("should handle invalid angle (<0° or >=360°)", () => {
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");

Choose a reason for hiding this comment

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

It is good that you used two expect statements here, for future tests this is a good practice.

});



7 changes: 7 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (denominator === 0) return false; // Avoid division by zero
if (numerator === 0) return true; // Zero is considered a proper fraction
if (numerator < 0 || denominator < 0) return false; // Negative fractions are not proper
return Math.abs(numerator) < Math.abs(denominator);

Choose a reason for hiding this comment

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

This looks good.

Here would the Math.abs(numerator) < Math.abs(denominator) check and the check for the denominator being zero be all that you need?

}

console.log(isProperFraction(0, 1));
console.log(isProperFraction(5,3));

module.exports = isProperFraction;
18 changes: 18 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 @@ -2,10 +2,28 @@ const isProperFraction = require("./2-is-proper-fraction");

test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
expect(isProperFraction(1, 2)).toEqual(true);
});

// Case 2: Identify Improper Fractions:

test("should return false for an improper fraction", () => {
expect(isProperFraction(5, 3)).toEqual(false);
expect(isProperFraction(3, 3)).toEqual(false);
});

// Case 3: Identify Negative Fractions:

test("should return false for negative fractions", () => {
expect(isProperFraction(-2, 3)).toEqual(false);
expect(isProperFraction(2, -3)).toEqual(false);
expect(isProperFraction(-2, -3)).toEqual(false);
});

// Case 4: Identify Equal Numerator and Denominator:

test("should return false when numerator and denominator are equal", () => {

Choose a reason for hiding this comment

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

The test coverage looks good.

expect(isProperFraction(4, 4)).toEqual(false);
});


17 changes: 16 additions & 1 deletion Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
//return 11;
if (card === 'A') {
return 11; // Ace can be 11 or 1, but we'll
}
else if (card === 'K' || card === 'Q' || card === 'J') {
return 10; // Face cards are worth 10
}
else {
return parseInt(card); // Number cards are worth their face value

Choose a reason for hiding this comment

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

This is a good start, how would we handle cases where there is a rank and a number? (e.g. 10♥)

What about situations where the rank is a number that we do not expect? e.g. 12

Copy link
Author

Choose a reason for hiding this comment

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

It throws an error: invalid card rank.

}
}
console.log(getCardValue('A'));
console.log(getCardValue('K'));
console.log(getCardValue('J'));
console.log(getCardValue('Q'));
console.log(getCardValue('B'));

module.exports = getCardValue;
Loading