We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 13e7832 commit f07827fCopy full SHA for f07827f
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,12 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ const lastTwoDigits = num % 100;
3
+ if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13)
4
+ return `${num}th`;
5
+ const lastDigit = num % 10;
6
+ if (lastDigit === 1) return `${num}st`;
7
+ if (lastDigit === 2) return `${num}nd`;
8
+ if (lastDigit === 3) return `${num}rd`;
9
10
}
11
12
module.exports = getOrdinalNumber;
0 commit comments