@@ -27,6 +27,7 @@ function getCardValue(card) {
2727 // Get the suit (last character) and rank (everything before it)
2828 const suit = card . slice ( - 1 ) ;
2929 const rank = card . slice ( 0 , - 1 ) ;
30+ console . log ( suit , rank ) ;
3031
3132 // Check that the suit is valid
3233 if ( ! validSuits . includes ( suit ) ) {
@@ -56,24 +57,6 @@ function getCardValue(card) {
5657 }
5758
5859 throw new Error ( "Invalid card" ) ;
59-
60- {
61- return Number ( rank ) ;
62- }
63-
64- // Invalid rank
65- throw new Error ( "Invalid card" ) ;
66- getCardValue ( "1♠" ) ;
67- getCardValue ( "11♣" ) ;
68- getCardValue ( "0♦" ) ;
69- getCardValue ( "B♥" ) ;
70- getCardValue ( "X♠" ) ;
71-
72- //invalid suit
73- getCardValue ( "AX" ) ;
74- getCardValue ( "5*" ) ;
75- getCardValue ( "10H" ) ;
76- getCardValue ( "QS" ) ;
7760}
7861
7962// The line below allows us to load the getCardValue function into tests in other files.
@@ -88,19 +71,32 @@ function assertEquals(actualOutput, targetOutput) {
8871 ) ;
8972}
9073
91- // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
92- // Examples:
93- assertEquals ( getCardValue ( "9♠" ) , 9 ) ;
94-
95- // Handling invalid cards
96- try {
97- getCardValue ( "invalid" ) ;
98-
99- // This line will not be reached if an error is thrown as expected
100- console . error ( "Error was not thrown for invalid card 😢" ) ;
101- } catch ( e ) {
102- console . log ( "Error thrown for invalid card 🎉" ) ;
103- }
104-
105- // What other invalid card cases can you think of?
106- //invalid rank
74+ // // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
75+ // // Examples:
76+ // assertEquals(getCardValue("9♠"), 9);
77+
78+ // // Handling invalid cards
79+ // try {
80+ // getCardValue("invalid");
81+
82+ // // This line will not be reached if an error is thrown as expected
83+ // console.error("Error was not thrown for invalid card 😢");
84+ // } catch (e) {
85+ // console.log("Error thrown for invalid card 🎉");
86+ // }
87+
88+ // // What other invalid card cases can you think of?
89+ // //invalid rank
90+ // getCardValue("1♠");
91+ // getCardValue("11♣");
92+ // getCardValue("0♦");
93+ // getCardValue("B♥");
94+ // getCardValue("X♠");
95+
96+ // //invalid suit
97+ // getCardValue("AX");
98+ // getCardValue("5*");
99+ // getCardValue("10H");
100+ // getCardValue("QS");
101+
102+ getCardValue ( "1♠" ) ;
0 commit comments