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 50749d9 commit 97a5210Copy full SHA for 97a5210
1 file changed
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,18 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ const lastDigits = num % 100;
3
+ if (lastDigits >= 11 && lastDigits <= 13) {
4
+ return num + "th";
5
+ }
6
+ switch (lastDigits % 10) {
7
+ case 1:
8
+ return num + "st";
9
+ case 2:
10
+ return num + "nd";
11
+ case 3:
12
+ return num + "rd";
13
+ default:
14
15
16
}
17
18
module.exports = getOrdinalNumber;
0 commit comments