Skip to content

Commit c555833

Browse files
committed
Further updates
1 parent aabad30 commit c555833

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
function getCardValue(card) {
2525
const suits = ["♠", "♥", "♦", "♣"]; // valid card suits
2626

27-
let suit = "";
28-
let rank = card;
29-
30-
if (suits.includes(card.slice(-1))) {
31-
suit = card.slice(-1); // gives me the last character and saves it in the suit variable.
32-
rank = card.slice(0, -1); // gets beginning character up to (not including) the last character and saves it in the rank variable.
33-
}
34-
35-
if (suit && !suits.includes(suit)) {
27+
// must have a valid suit
28+
if (!suits.includes(card.slice(-1))) {
3629
throw new Error("Error invalid card");
3730
}
3831

32+
const rank = card.slice(0, -1); // gets beginning character up to (not including) the last character and saves it in the rank variable.
33+
3934
// if card is an ace return 11
4035
if (rank === "A") {
4136
return 11;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test(`Should return 10 when given an face card`, () => {
2828
});
2929
// Case 3: Number Cards (2-10)
3030
test(`Should return numerical value when given an number card`, () => {
31-
expect(getCardValue("5")).toEqual(5);
31+
expect(() => getCardValue("5")).toThrow("Error invalid card");
3232
});
3333

3434
test(`Should return error if the card string is invalid`, () => {

0 commit comments

Comments
 (0)