Skip to content

Commit 0e0c2f5

Browse files
committed
created variables to store the values of repeatedly used expressions
1 parent 1c57e2b commit 0e0c2f5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
function getOrdinalNumber(num) {
2-
if (num % 10 === 1 && num % 100 !== 11) {
2+
let remainder1 = num % 10;
3+
let remainder2 = num % 100;
4+
if (remainder1 === 1 && remainder2 !== 11) {
35
// we also can use if (num[-1]===1 && num.slice(-2)!==11)
46
return num + "st";
5-
} else if (num % 10 === 2 && num % 100 !== 12) {
7+
} else if (remainder1 === 2 && remainder2 !== 12) {
68
// we also can use if (num[-1]===2 && num.slice(-2)!==12)
79
return num + "nd";
8-
} else if (num % 10 === 3 && num % 100 !== 13) {
10+
} else if (remainder1 === 3 && remainder2 !== 13) {
911
// we also can use if (num[-1]===3 && num.slice(-2)!==13)
1012
return num + "rd";
1113
} else {

0 commit comments

Comments
 (0)