Skip to content

London | 26-ITP-May | Alex Jamshidi | Sprint 3 | Practice tdd#1319

Open
Alex-Jamshidi wants to merge 4 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:Sprint-3/2-practice-tdd
Open

London | 26-ITP-May | Alex Jamshidi | Sprint 3 | Practice tdd#1319
Alex-Jamshidi wants to merge 4 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:Sprint-3/2-practice-tdd

Conversation

@Alex-Jamshidi
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Added solutions to Sprint 3 Practice TDD

@Alex-Jamshidi Alex-Jamshidi added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels May 12, 2026
Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - a couple of naming things to look at

return "1st";
if (!Number.isInteger(num) || num < 1) {throw new Error("Invalid number");}

let number = num.toString().slice(-2);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"num" and "number" are very hard to distinguish variables - it's not clear from their names what the differences between them are. Can you think how to improve this?

Copy link
Copy Markdown
Author

@Alex-Jamshidi Alex-Jamshidi May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed number to lastTwoDigits to make clearer what is happening


let number = num.toString().slice(-2);
if (number == 11 || number == 12 || number == 13) {return `${num}th`;}
if (number.slice(-1) == 1) {return `${num}st`;}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd extract a variable for that number.slice(-1) operation that you're repeating three times.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted and named lastDigit, code much more readable now

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 14, 2026
@Alex-Jamshidi Alex-Jamshidi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 14, 2026

const lastTwoDigits = num.toString().slice(-2);
const lastDigit = lastTwoDigits.slice(-1);
if (lastTwoDigits == 11 || lastTwoDigits == 12 || lastTwoDigits == 13) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We almost never want to use == in JavaScript, and almost always want to prefer === - can you do some research as to why, and update your code to use === instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I did know the difference here, == doesn't care about type, just value.
I've not really thought about being strict with this when I know what the code is going to do, but I realise it's much better to restrict as much as possible to prevent any incorrect data leaking through. I will aim to always use === going forward, expect in cases where type make not matter.

updated code. thanks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your code now pass its tests? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I check them!
No they didn't pass, because I was now trying to compare a string to number
converted strings to numbers to pass === check

tests all pass

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 15, 2026
@Alex-Jamshidi Alex-Jamshidi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 15, 2026
@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 15, 2026
@Alex-Jamshidi Alex-Jamshidi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 15, 2026
@illicitonion illicitonion added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Structuring-And-Testing-Data The name of the module. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants