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 eb8edda commit 4b70646Copy full SHA for 4b70646
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,16 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ if (num % 10 === 1 && num % 100 !== 11) {
3
+ // we also can use if (num[-1]===1 && num.slice(-2)!==11)
4
+ return num + "st";
5
+ } else if (num % 10 === 2 && num % 100 !== 12) {
6
+ // we also can use if (num[-1]===2 && num.slice(-2)!==12)
7
+ return num + "nd";
8
+ } else if (num % 10 === 3 && num % 100 !== 13) {
9
+ // we also can use if (num[-1]===3 && num.slice(-2)!==13)
10
+ return num + "rd";
11
+ } else {
12
+ return num + "th";
13
+ }
14
}
15
16
module.exports = getOrdinalNumber;
0 commit comments