Skip to content

Commit 6a29885

Browse files
committed
Fixed the code for invalid cards
1 parent 599d6db commit 6a29885

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,19 @@ try {
7171
} catch (e) {}
7272

7373
// What other invalid card cases can you think of?
74-
assertEquals(getCardValue("♦♦"), "invalid"); // throws an error for this example
75-
assertEquals(getCardValue("12"), "Error");
74+
// Handling invalid cards
75+
function assertThrows(testFunction) {
76+
let threw = false;
77+
78+
try {
79+
testFunction();
80+
} catch (error) {
81+
threw = true;
82+
}
83+
84+
console.assert(threw, "Expected function to throw an error.")
85+
}
86+
87+
assertThrows(() => getCardValue("1♣"));
88+
assertThrows(() => getCardValue("12"));
89+
assertThrows(() => getCardValue("♦3"));

0 commit comments

Comments
 (0)