London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | practice tdd#1265
London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 3 | practice tdd#1265djebsoft wants to merge 17 commits intoCodeYourFuture:mainfrom
Conversation
| return "1st"; | ||
| let remainder1 = num % 10; | ||
| let remainder2 = num % 100; | ||
| if (remainder1 === 1 && remainder2 !== 11) { |
There was a problem hiding this comment.
Best practice is to give variables descriptive (self-explanatory) names. Can you rename these two variables to make the code more readable.
| let remainder1 = num % 10; | ||
| let remainder2 = num % 100; | ||
| if (remainder1 === 1 && remainder2 !== 11) { | ||
| // we also can use if (num[-1]===1 && num.slice(-2)!==11) |
There was a problem hiding this comment.
Note: This expression (in the comment) is comparing a string to a number.
| // When the number does not end with 1, 2, or 3 | ||
| // Then the function should return a string by appending "th" to the number. | ||
|
|
||
| test("should append 'th' for all other numbers", () => { |
There was a problem hiding this comment.
This test description is what Jest output in the test report. It's better to replace "all other numbers" by the detailed condition described on line 50.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
| let lastDigit = num % 10; | ||
| let lastTwoDigits = num % 100; | ||
| if (lastDigit === 1 && lastTwoDigits !== 11) { | ||
| // we also can use if (num[-1]==="1" && num.slice(-2)!=="11") |
There was a problem hiding this comment.
Note: num[-1] is not the syntax to extract the last character in JavaScript. It will be evaluated to undefined.
Use .at(-1) or .slice(-1) instead.
There was a problem hiding this comment.
I changed it to .slice() instead of index to extract the last character
thank you
Learners, PR Template
Self checklist
Changelist
buit up my program test then wrote the code that will make them pass.
Questions