Skip to content

Commit 3590fb1

Browse files
author
russom
committed
An if statement added to the function to check if num is not negative or not a whole number or not a string first thing
1 parent ee69e69 commit 3590fb1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Sprint-3/2-practice-tdd/get-ordinal-number.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
function getOrdinalNumber(num) {
2+
if (num <= 0 || !Number.isInteger(num) || typeof num !== "number") {
3+
return "error";
4+
}
25
const lastDigit = num % 10;
36
const lastTwoDigits = num % 100;
47
if (lastDigit === 1 && lastTwoDigits !== 11) {
58
return `${num}st`;
69
}
7-
if (lastDigit === 2 && lastTwoDigits !== 12) {
10+
if (lastDigit === 2 && lastTwoDigits !== 12) {
811
return `${num}nd`;
912
}
10-
if (lastDigit === 3 && lastTwoDigits !== 13) {
11-
return `${num}rd`;
12-
}
13+
if (lastDigit === 3 && lastTwoDigits !== 13) {
14+
return `${num}rd`;
15+
}
1316
return `${num}th`;
1417
}
1518

0 commit comments

Comments
 (0)