Skip to content

Commit e2cd300

Browse files
author
russom
committed
wrong file
1 parent 0682a73 commit e2cd300

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
git commit -m "Remove Sprint 3 files from Sprint 2 branch"
2+
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
3+
4+
// Implement a function getCardValue, when given a string representing a playing card,
5+
// should return the numerical value of the card.
6+
7+
// A valid card string will contain a rank followed by the suit.
8+
// The rank can be one of the following strings:
9+
// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
10+
// The suit can be one of the following emojis:
11+
// "♠", "♥", "♦", "♣"
12+
// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦".
13+
14+
// When the card is an ace ("A"), the function should return 11.
15+
// When the card is a face card ("J", "Q", "K"), the function should return 10.
16+
// When the card is a number card ("2" to "10"), the function should return its numeric value.
17+
18+
// When the card string is invalid (not following the above format), the function should
19+
// throw an error.
20+
21+
// Acceptance criteria:
22+
// After you have implemented the function, write tests to cover all the cases, and
23+
// execute the code to ensure all tests pass.
24+
25+
function getCardValue(card) {
26+
// TODO: Implement this function
27+
}
28+
29+
// The line below allows us to load the getCardValue function into tests in other files.
30+
// This will be useful in the "rewrite tests with jest" step.
31+
module.exports = getCardValue;
32+
33+
// Helper functions to make our assertions easier to read.
34+
function assertEquals(actualOutput, targetOutput) {
35+
console.assert(
36+
actualOutput === targetOutput,
37+
`Expected ${actualOutput} to equal ${targetOutput}`
38+
);
39+
}
40+
41+
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
42+
// Examples:
43+
assertEquals(getCardValue("9♠"), 9);
44+
45+
// Handling invalid cards
46+
try {
47+
getCardValue("invalid");
48+
49+
// This line will not be reached if an error is thrown as expected
50+
console.error("Error was not thrown for invalid card 😢");
51+
} catch (e) {
52+
console.log("Error thrown for invalid card 🎉");
53+
}
54+
55+
// What other invalid card cases can you think of?

0 commit comments

Comments
 (0)