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