Skip to content

London | 26-ITP-Jan | Abdul Moiz | Sprint 3 | implement-and-rewrite#915

Open
A-Moiz wants to merge 11 commits intoCodeYourFuture:mainfrom
A-Moiz:coursework/sprint-3-implement-and-rewrite
Open

London | 26-ITP-Jan | Abdul Moiz | Sprint 3 | implement-and-rewrite#915
A-Moiz wants to merge 11 commits intoCodeYourFuture:mainfrom
A-Moiz:coursework/sprint-3-implement-and-rewrite

Conversation

@A-Moiz
Copy link

@A-Moiz A-Moiz commented Jan 27, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed all the exercises in implement-and-rewrite directory

Questions

N/A

@A-Moiz A-Moiz added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 27, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 27, 2026
@github-actions

This comment has been minimized.

@A-Moiz A-Moiz added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 27, 2026
Comment on lines 14 to 20
if (denominator === 0) {
return false;
} else if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
} else {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works.
Optional challenge: Simplify the code.

Comment on lines 24 to 25
function getCardValue(card) {
// TODO: Implement this function
const rank = card.slice(0, card.length - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

The requirements has changed a bit.
To ensure card is valid, you should also check if the last character is a valid suit character.

Comment on lines 28 to 29
} else if (Number(rank) >= 2 && Number(rank) < 10) {
return Number(rank);
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 or parsed into a valid integers.
Do you want to recognize these string values as valid ranks? If not, you will need to enforce stricter check.

To find out what these strings are, you can ask AI

What kinds of string values would make Number(rank) evaluate to 2 in JS?

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 an if statement beforehand to check typeof for the variable. If it fails it will throw an error.

Comment on lines +12 to +19
test(`should return true for proper fraction with positive numerator and denominator`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});

test(`should return false for improper fraction with positive numerator and denominator`, () => {
expect(isProperFraction(3, 2)).toEqual(false);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

What about negative numbers and different combinations of positive/negative/zero?

Think also what edge case to check?

Copy link
Author

Choose a reason for hiding this comment

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

Added extra tests for negative numerators/denominators and all are passing.

Comment on lines 32 to 34
} else {
return "Invalid card rank";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The new requirement is:

// When the card string is invalid (not following the above format), the function should
// throw an error.

Throwing an error is not the same as returning an error message.
Could you look up "How to throw an error in JS" and update your code accordingly?

Copy link
Author

Choose a reason for hiding this comment

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

Modified function and test case to throw error.

expect(getCardValue("11♥")).toEqual("Invalid card rank");
expect(getCardValue("Z♦")).toEqual("Invalid card rank");
});

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Could also include invalid cases that involves invalid suit character.

  • To test if a function can throw an error as expected, we could use .toThrow(). You can find out more about how to use .toThrow() here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 11, 2026
@A-Moiz A-Moiz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 14, 2026

function isProperFraction(numerator, denominator) {
// TODO: Implement this function
return Math.abs(numerator) < Math.abs(denominator) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

When an expression evaluates to a Boolean value, we can also just return the value of the expression:
return Math.abs(numerator) < Math.abs(denominator);

Comment on lines 36 to 39
const rankNum = Number(rank);
if (!Number.isNaN(rankNum) && rankNum >= 2 && rankNum < 10) {
return rankNum;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I added an if statement beforehand to check typeof for the variable. If it fails it will throw an error.

I don't see any statement involving typeof.

Currently, a card value like ""0x02♠" or "3.1416♠" can still pass the check on line 37.

Copy link
Author

Choose a reason for hiding this comment

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

Apologies, I got it mixed up with a different task. It is resolved now.

Comment on lines 32 to 38
test(`should return false for negative numerator`, () => {
expect(isProperFraction(-5, 2)).toEqual(false);
});

test(`should return false for negative numerator`, () => {
expect(isProperFraction(-5, 2)).toEqual(false);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Same test sample.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 14, 2026
@A-Moiz A-Moiz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 14, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Changes look good. Well done.

Comment on lines +38 to +42
!Number.isNaN(rankNum) &&
Number.isInteger(rankNum) &&
rankNum >= 2 &&
rankNum < 10 &&
rank === rankNum.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but an approach similar to that at line 29 is probably cleaner.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants