Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 2-practice-tdd - #1507
Open
lintsang wants to merge 2 commits into
Open
Manchester | 26-ITP-May | Yee Man Tsang | Sprint 3 | 2-practice-tdd#1507lintsang wants to merge 2 commits into
lintsang wants to merge 2 commits into
Conversation
|
Don't forget to add the (I've picked this up today but bear it in mind for future!) |
Liam310
reviewed
Jul 14, 2026
Liam310
reviewed
Jul 14, 2026
Liam310
reviewed
Jul 14, 2026
Comment on lines
+4
to
+40
| if (String(num).length > 1) { | ||
| //check if the number has more than 1 digit | ||
| onesDigit = Number(String(num).slice(-1)); //extract the figure at the tens digit, and convert it into a number. | ||
| const tensDigit = Number(String(num).slice(-2, -1)); //extract the figure at the tens digit, and convert it into a number. | ||
|
|
||
| if (onesDigit == 1) { | ||
| if (tensDigit == 1) { | ||
| return num + "th"; | ||
| } else { | ||
| return num + "st"; | ||
| } | ||
| } else if (onesDigit == 2) { | ||
| if (tensDigit == 1) { | ||
| return num + "th"; | ||
| } | ||
| return num + "nd"; | ||
| } else if (onesDigit == 3) { | ||
| if (tensDigit == 1) { | ||
| return num + "th"; | ||
| } | ||
| return num + "rd"; | ||
| } else { | ||
| ("th"); | ||
| } | ||
| } else if (String(num).length == 1) { | ||
| onesDigit = Number(String(num)[0]); //extract the figure at the tens digit, and convert it into a number. | ||
| if (onesDigit == 1) { | ||
| return num + "st"; | ||
| console.log("Yeah youre in"); | ||
| } else if (onesDigit == 2) { | ||
| return num + "nd"; | ||
| } else if (onesDigit == 3) { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } |
There was a problem hiding this comment.
This is a mostly working solution, but with a lot of nested if statements it can be quite hard to follow the logic of it.
A few things to consider:
- You repeat the same
if (tensDigit == 1) { return num + "th" }line, which suggests if the tens digit of the number is 1, you're always doing the same thing. How you might you simplify this so you only need to perform that check once? - On line 25 you have an
elsestatement that doesn't contain any logic. What should that statement be doing? Why wasn't it caught by the tests? - The logic you have for numbers whose "length" is 1 is very similar to the logic you have for numbers whose "length" is more than 1. You could definitely make this less repetitive!
- In a lot of places you have used
==instead of===- I asked you in a previous submission what the difference was and what would be better - same question applies here! - You've got a leftover
console.logon line 32 - get rid!
Author
There was a problem hiding this comment.
Thanks for guiding me on this problem. I am having some insights for how to make this kind of statement in the future.
There was a problem hiding this comment.
This is so much better Lin! I hope you are happy with this improvement 😄
Liam310
reviewed
Jul 14, 2026
Liam310
reviewed
Jul 14, 2026
Liam310
reviewed
Jul 14, 2026
|
@lintsang Really nice improvements here Lin - I have no further comments so happy to mark as Complete ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
Finished all exercises in 2-practice-tdd folder