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 7f2b357 commit 23a26c6Copy full SHA for 23a26c6
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,19 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ const lastDigit = num % 10;
3
+ const lastTwoDigits = num % 100;
4
+
5
+ if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) {
6
+ return `${num}th`;
7
+ } else if (lastDigit === 1) {
8
+ return `${num}st`;
9
+ } else if (lastDigit === 2) {
10
+ return `${num}nd`;
11
+ } else if (lastDigit === 3) {
12
+ return `${num}rd`;
13
+ } else {
14
15
16
+ }
17
}
18
19
module.exports = getOrdinalNumber;
0 commit comments