File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Sprint-3/2-mandatory-rewrite Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 11function getCardValue ( card ) {
2- // replace with your code from key-implement
3- return 11 ;
2+ // replace with your code from key-implement
3+ // return 11; // always return 11 for testing purposes that is wrong
4+ const rank = card . slice ( 0 , - 1 ) ; // Extract rank (everything except the last character)
5+ if ( rank === "A" ) return 11 ; // handle Ace as 11
6+ if ( [ "K" , "Q" , "J" ] . includes ( rank ) ) return 10 ; // handle face cards as 10
7+ const numerincRank = parseInt ( rank ) ; //Handle number cards 2–9
8+ if ( numerincRank >= 2 && numerincRank <= 9 ) {
9+ return numerincRank ; // Return the numeric value for cards 2-9
10+ }
11+ // Invalid card rank
12+ return 0 ;
413}
5- module . exports = getCardValue ;
14+ module . exports = getCardValue ;
15+
16+ // // Test cases
17+ console . log ( getCardValue ( "A♠" ) ) ; // 11
18+ console . log ( getCardValue ( "7♥" ) ) ; // 7
19+ console . log ( getCardValue ( "K♦" ) ) ; // 10
20+ console . log ( getCardValue ( "A♣" ) ) ; // 11
You can’t perform that action at this time.
0 commit comments