@@ -25,11 +25,25 @@ function getCardValue(card) {
2525 const rank = card . slice ( 0 , - 1 ) ;
2626 const suit = card . slice ( - 1 ) ;
2727
28- const vaildSuits = [ "♠" , "♥" , "♦" , "♣" ] ;
29- const vailRanks = [ "A" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "J" , "Q" , "k" ] ;
30-
31- if ( ! vaildSuits . includes ( suit ) || ! validRanks . inculdes ( rank ) ) {
32- throw new Error ( "Invaild card" ) ;
28+ const vaildSuits = [ "♠" , "♥" , "♦" , "♣" ] ;
29+ const vailRanks = [
30+ "A" ,
31+ "2" ,
32+ "3" ,
33+ "4" ,
34+ "5" ,
35+ "6" ,
36+ "7" ,
37+ "8" ,
38+ "9" ,
39+ "10" ,
40+ "J" ,
41+ "Q" ,
42+ "K" ,
43+ ] ;
44+
45+ if ( ! vaildSuits . includes ( suit ) || ! vailRanks . includes ( rank ) ) {
46+ throw new Error ( "Invalid card" ) ;
3347 }
3448 if ( rank === "A" ) return 11 ;
3549 if ( rank === "J" || rank === "Q" || rank === "K" ) return 10 ;
@@ -39,11 +53,9 @@ const vaildSuits = ["♠", "♥", "♦", "♣"];
3953
4054module . exports = getCardValue ;
4155
42-
4356// The line below allows us to load the getCardValue function into tests in other files.
4457// This will be useful in the "rewrite tests with jest" step.
4558
46-
4759// Helper functions to make our assertions easier to read.
4860function assertEquals ( actualOutput , targetOutput ) {
4961 console . assert (
@@ -56,17 +68,16 @@ function assertEquals(actualOutput, targetOutput) {
5668// Examples:
5769assertEquals ( getCardValue ( "9♠" ) , 9 ) ;
5870//Test
59- assertEquals ( getCardvalue ( "A♠" ) , 11 ) ;
60- assertEquals ( getCardEqual ( "J♣), 10);
61- assertEquals ( getCardequal ( "10♥" ) , 10 ) ;
71+ assertEquals ( getCardValue ( "A♠" ) , 11 ) ;
72+ assertEquals ( getCardValue ( "J♣" ) , 10 ) ;
73+ assertEquals ( getCardValue ( "10♥" ) , 10 ) ;
6274
6375// Handling invalid cards
6476try {
6577 getCardValue ( "invalid" ) ;
66-
6778
6879 // This line will not be reached if an error is thrown as expected
6980 console . error ( "Error was not thrown for invalid card" ) ;
7081} catch ( e ) { }
7182
72- // What other invalid card cases can you think of?
83+ // What other invalid card cases can you think of?
0 commit comments