Skip to content

Commit 01e4e00

Browse files
added tests and renamed variable
1 parent 7f76795 commit 01e4e00

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function getOrdinalNumber(num) {
22
// Check if input is a number
3-
if (typeof num !== "number" || isNaN(num)) {
3+
if (typeof num !== "number" || isNaN(num)) || !Number.isInteger(num) || !Number.isFinite(num)) {
44
throw new Error("Input must be a valid number");
55
}
66

7-
const j = num % 10; // checks what last number is
8-
const k = 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 = % 100; // checks what last two numbers are, needed to check for 11
99

10-
if (k === 11 || k === 12 || k === 13) {
10+
if (last2num === 11 || last2num === 12 || last2num === 13) {
1111
return num + "th";
1212
}
13-
if (j === 1) return num + "st";
14-
if (j === 2) return num + "nd";
15-
if (j === 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)