File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 2323
2424function getCardValue ( card ) {
2525 // TODO: Implement this function
26+ const rank = card . slice ( 0 , - 1 ) ;
27+ const suit = card . slice ( - 1 ) ;
28+ if ( rank === "A" ) {
29+ return 11 ;
30+ }
31+ if ( rank === "J" || rank === "Q" || rank === "K" ) {
32+ return 10 ;
33+ }
34+ return parseInt ( rank ) ;
2635}
2736
2837// The line below allows us to load the getCardValue function into tests in other files.
5059} catch ( e ) { }
5160
5261// What other invalid card cases can you think of?
62+ assertEquals ( getCardValue ( "A" ) , 11 ) ; // Missing suit
63+ try {
64+ getCardValue ( "11♠" ) ; // Invalid rank
65+ console . error ( "Error was not thrown for invalid rank" ) ;
66+ } catch ( e ) { }
67+
68+ try { getCardValue ( "9X" ) ; // Invalid suit
69+ console . error ( "Error was not thrown for invalid suit" ) ;
70+ } catch ( e ) { }
You can’t perform that action at this time.
0 commit comments