Skip to content

Commit 1a6131d

Browse files
committed
added tests for ordinal numbers up to 20, then created a function to get the ordinal numbers
1 parent 51060d9 commit 1a6131d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
if (num === 1) {
3+
return "1st";
4+
} else if (num === 2) {
5+
return "2nd";
6+
} else if (num === 3) {
7+
console.log(num);
8+
return "3rd";
9+
} else if (num > 3 || num < 21) {
10+
return `${num}th`;
11+
}
312
}
413

514
module.exports = getOrdinalNumber;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ const getOrdinalNumber = require("./get-ordinal-number");
1111
test("should return '1st' for 1", () => {
1212
expect(getOrdinalNumber(1)).toEqual("1st");
1313
});
14+
15+
test("should return '2nd' for 2", () => {
16+
expect(getOrdinalNumber(2)).toEqual("2nd");
17+
});
18+
19+
test("should return '3rd' for 3", () => {
20+
expect(getOrdinalNumber(3)).toEqual("3rd");
21+
});
22+
23+
test("should return any number between 4 and 20 with a suffix of 'th' at end of number", () => {
24+
expect(getOrdinalNumber(10)).toEqual("10th");
25+
});

0 commit comments

Comments
 (0)