-
-
Notifications
You must be signed in to change notification settings - Fork 391
London | 25 -ITP-May | Dagim Daniel | Sprint 3 | implement and rewrite-test with jest #1473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e3ae6db
c822d53
3538f28
b37f1b2
927466a
3c016e7
4d1bf8c
0b7c108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,31 @@ | |
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
| const value = card.slice(0, -1).toUpperCase(); | ||
| const validSuits = "♠,♥,♦,♣".split(","); | ||
| const suit = card.slice(-1); | ||
|
|
||
| if (!validSuits.includes(suit)) { | ||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| const faceCardValues = { A: 11, J: 10, Q: 10, K: 10 }; | ||
|
|
||
| if ( | ||
| faceCardValues[value] === undefined && | ||
| (Number(value) < 2 || Number(value) > 10) | ||
| ) { | ||
| throw new Error("Invalid card"); | ||
| } | ||
|
|
||
| if (faceCardValues[value] !== undefined) { | ||
| return faceCardValues[value]; | ||
| } | ||
|
|
||
| const numvalue = Number(value); | ||
| if (numvalue >= 2 && numvalue <= 10) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this if condition need to be here? (Hint: compare it to the earlier if conditions)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess so, because the other if condition was for throw error. with out this if condition it wouldn't give us the the numvalue within this scop |
||
| return numvalue; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -41,6 +66,13 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
|
|
||
| assertEquals(getCardValue("A♥"), 11); | ||
| assertEquals(getCardValue("10♠"), 10); | ||
|
|
||
| assertEquals(getCardValue("2♠"), 2); | ||
| assertEquals(getCardValue("K♠"), 10); | ||
| assertEquals(getCardValue("q♦"), 10); | ||
| assertEquals(getCardValue("J♣"), 10); | ||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you remember to format this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't get you, LonMcGregor sorry