Skip to content

Commit 7eda399

Browse files
committed
implement function to get ordinal numbers
1 parent 4189d74 commit 7eda399

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
let output;
3+
if (num % 100 === 11 || num % 100 === 12 || num % 100 === 13) {
4+
output = `${num}th`;
5+
} else if (num % 10 === 1) {
6+
output = `${num}st`;
7+
} else if (num % 10 === 2) {
8+
output = `${num}nd`;
9+
} else if (num % 10 === 3) {
10+
output = `${num}rd`;
11+
} else {
12+
output = `${num}th`;
13+
}
14+
return output;
315
}
416

517
module.exports = getOrdinalNumber;
18+
19+
//check if code runs
20+
console.log(getOrdinalNumber(1));

0 commit comments

Comments
 (0)