File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 88// write one test at a time, and make it pass, build your solution up methodically
99// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010function getCardValue ( card ) {
11+ // Extract the rank (all characters except the last one which is the suit)
12+ const rank = card . slice ( 0 , - 1 ) ;
13+
1114 if ( rank === "A" ) {
1215 return 11 ;
1316 }
17+
18+ const numValue = parseInt ( rank , 10 ) ;
19+ if ( numValue >= 2 && numValue <= 10 ) {
20+ return numValue ;
21+ }
1422}
1523
1624// The line below allows us to load the getCardValue function into tests in other files.
@@ -39,6 +47,7 @@ assertEquals(aceofSpades, 11);
3947// When the function is called with such a card,
4048// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4149const fiveofHearts = getCardValue ( "5♥" ) ;
50+ assertEquals ( fiveofHearts , 5 ) ;
4251// ====> write your test here, and then add a line to pass the test in the function above
4352
4453// Handle Face Cards (J, Q, K):
You can’t perform that action at this time.
0 commit comments