Skip to content

Commit f3f8b47

Browse files
refactor: implement getOrdinalNumber function to return correct ordinal suffixes
1 parent 22f8e4a commit f3f8b47

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sprint-3/2-practice-tdd/get-ordinal-number.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@ function getOrdinalNumber(num) {
66
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){
77
return num + "St";
88
}
9+
// will return "St" if the number ends in 1.
10+
if (lastDigit === 1){
11+
return num + "st";
12+
}
13+
// will return "Nd" if the number ends in 2.
14+
if (lastDigit === 2){
15+
return num + "nd";
16+
}
17+
// will return "Rd" if the number ends in 3.
18+
if (lastDigit === 3){
19+
return num + "rd";
20+
}
921

22+
// will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th".
23+
return num + "th";
1024
}
1125

1226
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)