Skip to content

Commit 4b4d8da

Browse files
committed
2 proper fraction exercise done
1 parent a805d98 commit 4b4d8da

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
11+
if(typeof(numerator) != "number" || typeof(denominator) != "number") {
12+
return "[ wrong input ]";
13+
}
14+
if (numerator < denominator ) {
1215
return true;
1316
}
17+
return false;
1418
}
1519

1620
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -47,13 +51,27 @@ assertEquals(improperFraction, false);
4751
// 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.
4852
const negativeFraction = isProperFraction(-4, 7);
4953
// ====> complete with your assertion
54+
assertEquals(negativeFraction, true);
5055

5156
// Equal Numerator and Denominator check:
5257
// Input: numerator = 3, denominator = 3
5358
// target output: false
5459
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5560
const equalFraction = isProperFraction(3, 3);
5661
// ====> complete with your assertion
62+
assertEquals(equalFraction, false);
5763

5864
// Stretch:
5965
// What other scenarios could you test for?
66+
67+
// Try 0 and a negative number check:
68+
// Input: numerator = -10, denominator = 0
69+
// target output: true
70+
const tryZero = isProperFraction(-10, 0);
71+
assertEquals(tryZero, true);
72+
73+
// check if inputs are proper numbers:
74+
// Input: numerator = "hello", denominator = 4 (any number)
75+
//target output: string
76+
const tryString = isProperFraction("hello", 4);
77+
assertEquals(tryString, "[ wrong input ]");

0 commit comments

Comments
 (0)