File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1010function getCardValue ( card ) {
1111 const rank = card . slice ( 0 , - 1 ) ; // get the rank (before the suit symbol)
1212
13+
14+ const num = Number ( rank ) ; // converting to a number.
15+
1316 if ( ! isNaN ( rank ) ) {
14- return Number ( rank ) ; // Number card
17+ return num ; // Number card
1518 }
1619
1720 if ( rank === "J" || rank === "Q" || rank === "K" ) {
1821 return 10 ; // Face cards
1922 }
2023
21- if ( rank === "A" ) return 11 ; // Ace
24+ if ( rank === "A" ) return 11 ; // Ace
2225
2326 // Anything else is invalid
24- throw new Error ( "Invalid card rank" ) ;
25- }
27+ throw new Error ( "Invalid card rank" )
28+
29+ }
30+
31+ console . log ( Number ( "0x002" ) ) ;
32+ console . log ( Number ( "2.1" ) ) ;
33+ console . log ( Number ( "9e1" ) ) ;
34+ console . log ( Number ( "0002" ) ) ;
35+
36+
2637
2738// if the rank is not a number or a face card, throw an error(invalid card rank).
2839
You can’t perform that action at this time.
0 commit comments