Skip to content

London | 26 - ITP-MAY | Ebrahim Moqbel | Sprint 3 | Implement and ewrite tests - #1586

Open
Ebrahim-Moqbel wants to merge 9 commits into
CodeYourFuture:mainfrom
Ebrahim-Moqbel:coursework/sprint-3
Open

London | 26 - ITP-MAY | Ebrahim Moqbel | Sprint 3 | Implement and ewrite tests#1586
Ebrahim-Moqbel wants to merge 9 commits into
CodeYourFuture:mainfrom
Ebrahim-Moqbel:coursework/sprint-3

Conversation

@Ebrahim-Moqbel

Copy link
Copy Markdown

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 the implement and rewrite file with fixing a bug

Questions

N/A

@Ebrahim-Moqbel Ebrahim-Moqbel added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Jul 29, 2026
@Luro91 Luro91 added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jul 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done on writing test cases for the border cases.


function getCardValue(card) {
// TODO: Implement this function
let rank = card.slice(0,-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why are you using let here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

creating a variable rank and assign the last element which it the face in it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I also could use const as I won't be updating the variables latter on.

function getCardValue(card) {
// TODO: Implement this function
let rank = card.slice(0,-1);
let cardFace = card[card.length - 1];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The indendation of this line is not consistent with the rest of the code. How can you ensure to always format your code consistently?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks sort it!

Comment on lines +35 to +37
if (+rank >= 2 && +rank <= 9) {
return +rank;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is the purpose of +rank?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

converting the string rank to a number.

Comment on lines +41 to +42
if (!["♠", "♥", "♦", "♣"].includes(cardFace)) {
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does this code do?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In code line number 38 a condition check that the elements k,10,Q,J are in the rank, if so will be returning number 10.
in code line number 41 will be matching the card face if any of the elements are not in CardFace will stop everything and throw an error.

Comment on lines +26 to +30
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("5X")).toThrow("Invalid card ")}); //invalid suit
expect(() => getCardValue("1♠")).toThrow("Invalid card "); //invalid rank
expect(() => getCardValue("3")).toThrow("Invalid card "); //missing suit
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Vs code shows me an error here. How can you fix it?
Declaration or statement expected.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

there was a closing curly bracket and parenthese in line 27.

expect(getCardValue("K♠")).toEqual(10);
})
// Invalid Cards
test(`Should throw an error when given an invalid card`, () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What other invalid cases could you test (which other ranks are invalid and what about a missing rank)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have added another case in line 27 for testing a missing rank. other invalid cases could be negative ranks.

@Luro91 Luro91 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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Structuring-And-Testing-Data The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants