Skip to content

Commit f55e9b5

Browse files
made variables into camelCase and shortened the code for checking 11, 12,13
1 parent e947150 commit f55e9b5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ function getOrdinalNumber(num) {
44
throw new Error("Input must be a valid number");
55
}
66

7-
const lastnum = num % 10; // checks what last number is
8-
const last2num = num % 100; // checks what last two numbers are, needed to check for 11
7+
const lastNum = num % 10; // checks what last number is
8+
const last2Num = num % 100; // checks what last two numbers are, needed to check for 11
99

10-
if (last2num === 11 || last2num === 12 || last2num === 13) {
10+
if (last2Num >= 11 && last2Num <= 13) {
1111
return num + "th";
1212
}
13-
if (lastnum === 1) return num + "st";
14-
if (lastnum === 2) return num + "nd";
15-
if (lastnum === 3) return num + "rd";
13+
if (lastNum === 1) return num + "st";
14+
if (lastNum === 2) return num + "nd";
15+
if (lastNum === 3) return num + "rd";
1616

1717
return num + "th";
1818
}

0 commit comments

Comments
 (0)