File tree Expand file tree Collapse file tree
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,26 +30,27 @@ function getCardValue(card) {
3030 if ! ( [ "♠" , "♥" , "♦" , "♣" ] . includes ( suit ) ) {
3131 throw new Error ( "Invalid card suit" ) ;
3232 }
33-
34- // Ace value
35- if ( rank === "A" ) {
36- return 11 ;
33+ else
34+ {
35+ // Ace value
36+ if ( rank === "A" ) {
37+ return 11 ;
38+ }
39+
40+ // Face card values
41+ if ( [ "J" , "Q" , "K" ] . includes ( rank ) ) {
42+ return 10 ;
43+ }
44+
45+ // Number card values ("2" through "10")
46+ const numericValue = parseInt ( rank , 10 ) ;
47+ if ( ! isNaN ( numericValue ) && numericValue >= 2 && numericValue <= 10 ) {
48+ return numericValue ;
49+ }
50+
51+ throw new Error ( "Invalid card string" ) ;
3752 }
3853
39- // Face card values
40- if ( [ "J" , "Q" , "K" ] . includes ( rank ) ) {
41- return 10 ;
42- }
43-
44- // Number card values ("2" through "10")
45- const numericValue = parseInt ( rank , 10 ) ;
46- if ( ! isNaN ( numericValue ) && numericValue >= 2 && numericValue <= 10 ) {
47- return numericValue ;
48- }
49-
50- throw new Error ( "Invalid card string" ) ;
51-
52-
5354}
5455
5556// The line below allows us to load the getCardValue function into tests in other files.
You can’t perform that action at this time.
0 commit comments