Skip to content

Commit c9d4307

Browse files
fixed some bugs and added some cases answering the reviewer Qs and suggestions.
1 parent 12433ce commit c9d4307

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26-
let rank = card.slice(0,-1);
27-
let cardFace = card[card.length - 1];
26+
const rank = card.slice(0,-1);
27+
const cardFace = card[card.length - 1];
2828

2929
if (!["♠", "♥", "♦", "♣"].includes(cardFace)) {
3030
throw new Error(`Invalid card face: ${cardFace}`);
@@ -39,10 +39,11 @@ function getCardValue(card) {
3939
return 10;
4040
}
4141
if (!["♠", "♥", "♦", "♣"].includes(cardFace)) {
42-
}
43-
throw new Error(`Invalid card`);
42+
throw new Error(`Invalid card`);
4443
}
4544

45+
46+
4647

4748
// The line below allows us to load the getCardValue function into tests in other files.
4849
// This will be useful in the "rewrite tests with jest" step.

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ test(`Should return 10 when given a face card (J, Q, K)`, () => {
2424
})
2525
// Invalid Cards
2626
test(`Should throw an error when given an invalid card`, () => {
27-
expect(() => getCardValue("5X")).toThrow("Invalid card ")}); //invalid suit
27+
expect(() => getCartValue("♠").toThrow("Invalid card"));
28+
expect(() => getCardValue("5X")).toThrow("Invalid card "); //invalid suit
2829
expect(() => getCardValue("1♠")).toThrow("Invalid card "); //invalid rank
2930
expect(() => getCardValue("3")).toThrow("Invalid card "); //missing suit
3031
})

0 commit comments

Comments
 (0)