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- const rank = card . slice ( 0 , - 1 ) ;
11+ const rank = card . slice ( 0 , - 1 ) ;
1212 if ( rank === "A" ) {
1313 return 11 ;
1414 }
15- if ( rank === "J" || rank === "Q" || rank === "K" )
16- {
15+ if ( rank === "J" || rank === "Q" || rank === "K" ) {
1716 return 10 ;
1817 }
19- const convertTheStringtoNumber = Number ( rank ) ;
20- if ( convertTheStringtoNumber >= 2 && convertTheStringtoNumber <= 10 ) {
21- return convertTheStringtoNumber ;
22- }
23- else
24- {
25- return "Invalid card rank" ;
26- }
18+ const convertTheStringtoNumber = Number ( rank ) ;
19+ if ( convertTheStringtoNumber >= 2 && convertTheStringtoNumber <= 10 ) {
20+ return convertTheStringtoNumber ;
21+ } else {
22+ return "Invalid card rank" ;
23+ }
2724}
2825// The line below allows us to load the getCardValue function into tests in other files.
2926// This will be useful in the "rewrite tests with jest" step.
@@ -52,17 +49,17 @@ assertEquals(aceofSpades, 11);
5249// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
5350const fiveofHearts = getCardValue ( "5♥" ) ;
5451// ====> write your test here, and then add a line to pass the test in the function above
55- assertEquals ( fiveofHearts , 5 ) ;
52+ assertEquals ( fiveofHearts , 5 ) ;
5653// Handle Face Cards (J, Q, K):
5754// Given a card with a rank of "10," "J," "Q," or "K",
5855// When the function is called with such a card,
5956// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
6057const jackofHearts = getCardValue ( "J♥" ) ;
61- assertEquals ( jackofHearts , 10 ) ;
58+ assertEquals ( jackofHearts , 10 ) ;
6259const queenofSpades = getCardValue ( "Q♠" ) ;
63- assertEquals ( queenofSpades , 10 ) ;
60+ assertEquals ( queenofSpades , 10 ) ;
6461const kingofSpades = getCardValue ( "K♠" ) ;
65- assertEquals ( kingofSpades , 10 ) ;
62+ assertEquals ( kingofSpades , 10 ) ;
6663// Handle Ace (A):
6764// Given a card with a rank of "A",
6865// When the function is called with an Ace,
@@ -74,4 +71,4 @@ assertEquals(aceofHearts, 11);
7471// When the function is called with such a card,
7572// Then it should throw an error indicating "Invalid card rank."
7673const invalidCards = getCardValue ( "B♥" ) ;
77- assertEquals ( invalidCards , "Invalid card rank" ) ;
74+ assertEquals ( invalidCards , "Invalid card rank" ) ;
0 commit comments