You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
48
48
constnegativeFraction=isProperFraction(-4,7);
49
-
// ====> complete with your assertion
49
+
assertEquals(negativeFraction,true);
50
50
51
51
// Equal Numerator and Denominator check:
52
52
// Input: numerator = 3, denominator = 3
53
53
// target output: false
54
54
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
55
55
constequalFraction=isProperFraction(3,3);
56
-
// ====> complete with your assertion
56
+
assertEquals(equalFraction,false);
57
57
58
58
// Stretch:
59
59
// What other scenarios could you test for?
60
+
61
+
62
+
// // Stretch Scenarios:
63
+
64
+
// Stretch 1: Zero in numerator
65
+
// Input: numerator = 0, denominator = 5
66
+
// target output: true
67
+
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). Any fraction with zero numerator is proper (except when denominator is also zero).
68
+
constzeroNumerator=isProperFraction(0,5);
69
+
assertEquals(zeroNumerator,true);
70
+
71
+
// Stretch 2: Negative denominator
72
+
// Input: numerator = 2, denominator = -5
73
+
// target output: false
74
+
// Explanation: The fraction 2/-5 equals -0.4, but when comparing 2 < -5, this is false. The function compares the actual values, not absolute values.
Copy file name to clipboardExpand all lines: Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
+35-1Lines changed: 35 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,23 @@
8
8
// write one test at a time, and make it pass, build your solution up methodically
9
9
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
10
10
functiongetCardValue(card){
11
+
// Handle "10" case first since it has two characters
12
+
if(card.startsWith("10")){
13
+
return10;
14
+
}
15
+
16
+
constrank=card[0];// Extract the rank from the card string
11
17
if(rank==="A"){
12
18
return11;
13
19
}
20
+
if(rank>="2"&&rank<="9"){
21
+
returnparseInt(rank);
22
+
}
23
+
if(rank==="J"||rank==="Q"||rank==="K"){
24
+
return10;
25
+
}
26
+
27
+
thrownewError("Invalid card rank.");
14
28
}
15
29
16
30
// The line below allows us to load the getCardValue function into tests in other files.
@@ -26,6 +40,7 @@ function assertEquals(actualOutput, targetOutput) {
26
40
`Expected ${actualOutput} to equal ${targetOutput}`
27
41
);
28
42
}
43
+
29
44
// Acceptance criteria:
30
45
31
46
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
0 commit comments