Skip to content

Commit 5eea892

Browse files
committed
changes to ordinal numbers
1 parent e448679 commit 5eea892

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ function getOrdinalNumber(num) {
44
const lastTwoDigits = num % 100;
55
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) return num + "th";
66

7-
if (num % 10 === 1) {
7+
const lastDigit = num % 10;
8+
if (lastDigit === 1) {
89
return num + "st";
910
}
10-
if (num % 10 === 2) {
11+
if (lastDigit === 2) {
1112
return num + "nd";
1213
}
13-
if (num % 10 === 3) {
14+
if (lastDigit === 3) {
1415
return num + "rd";
1516
}
1617
return num + "th";

0 commit comments

Comments
 (0)