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 bc5c9eb commit c953391Copy full SHA for c953391
1 file changed
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,17 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ let strNum;
3
+ const lastNum = num % 10;
4
+ const lastTwoNums = num % 100;
5
+ if (lastNum === 1 && lastTwoNums !== 11) {
6
+ strNum = `${String(num)}st`;
7
+ } else if (lastNum === 2 && lastTwoNums !== 12) {
8
+ strNum = `${String(num)}nd`;
9
+ } else if (lastNum === 3 && lastTwoNums !== 13) {
10
+ strNum = `${String(num)}rd`;
11
+ } else {
12
+ strNum = `${String(num)}th`;
13
+ }
14
+ return strNum;
15
}
16
17
module.exports = getOrdinalNumber;
0 commit comments