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