Skip to content

Commit 366b81a

Browse files
author
Payman IB
committed
Add error handling for zero denominator in isProperFraction function
1 parent 4c6389a commit 366b81a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (Math.abs(numerator) < Math.abs(denominator)) {
12-
return true;
13-
}
14-
else if (numerator >= denominator) {
15-
return false;
11+
if (denominator === 0) {
12+
throw new Error("Denominator cannot be zero");
1613
}
14+
15+
return Math.abs(numerator) < Math.abs(denominator);
1716
}
1817

1918
// The line below allows us to load the isProperFraction function into tests in other files.

0 commit comments

Comments
 (0)