File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
Sprint-3/1-implement-and-rewrite-tests Expand file tree Collapse file tree 2 files changed +7
-10
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-
12- const rank = card . slice ( 0 , - 1 ) ; // Extract rank before the suit
11+ const rank = card . slice ( 0 , - 1 ) ; // Get everything except the last char (the suit)
1312
1413 if ( rank === "A" ) {
1514 return 11 ;
@@ -18,10 +17,8 @@ function getCardValue(card) {
1817 } else if ( ! isNaN ( rank ) && Number ( rank ) >= 2 && Number ( rank ) <= 9 ) {
1918 return Number ( rank ) ;
2019 } else {
21- throw new Error ( ' Invalid card rank: "${rank}"' ) ; //rather than just "Invalid card rank" we can show the actual rank that was invalid
20+ throw new Error ( ` Invalid card rank: "${ rank } "` ) ; // rather than just "Invalid card rank" we can show the actual rank that was invalid
2221 }
23-
24-
2522}
2623
2724// The line below allows us to load the getCardValue function into tests in other files.
Original file line number Diff line number Diff line change @@ -29,23 +29,23 @@ test("should return 11 for Ace (A)", () => {
2929// Case 5: Handle Invalid Cards:
3030
3131test ( "should throw an error for invalid input '1♣'" , ( ) => {
32- expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( " Invalid card" ) ;
32+ expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( ' Invalid card rank: "1"' ) ;
3333} ) ;
3434
3535test ( "should throw an error for invalid input '1♦'" , ( ) => {
36- expect ( ( ) => getCardValue ( "1♦" ) ) . toThrow ( " Invalid card" ) ;
36+ expect ( ( ) => getCardValue ( "1♦" ) ) . toThrow ( ' Invalid card rank: "1"' ) ;
3737} ) ;
3838
3939test ( "should throw an error for invalid input 'B♥'" , ( ) => {
40- expect ( ( ) => getCardValue ( "B♥" ) ) . toThrow ( " Invalid card" ) ;
40+ expect ( ( ) => getCardValue ( "B♥" ) ) . toThrow ( ' Invalid card rank: "B"' ) ;
4141} ) ;
4242
4343test ( "should throw an error for invalid input 'Z♠'" , ( ) => {
44- expect ( ( ) => getCardValue ( "Z♠" ) ) . toThrow ( " Invalid card" ) ;
44+ expect ( ( ) => getCardValue ( "Z♠" ) ) . toThrow ( ' Invalid card rank: "Z"' ) ;
4545} ) ;
4646
4747test ( "should throw an error for empty string" , ( ) => {
48- expect ( ( ) => getCardValue ( "" ) ) . toThrow ( " Invalid card" ) ;
48+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( ' Invalid card rank: ""' ) ;
4949} ) ;
5050
5151
You can’t perform that action at this time.
0 commit comments