Skip to content

London | 26-ITP-Jan | Abdul Moiz | Sprint 2 | Sprint 2#911

Open
A-Moiz wants to merge 8 commits intoCodeYourFuture:mainfrom
A-Moiz:coursework/sprint-2
Open

London | 26-ITP-Jan | Abdul Moiz | Sprint 2 | Sprint 2#911
A-Moiz wants to merge 8 commits intoCodeYourFuture:mainfrom
A-Moiz:coursework/sprint-2

Conversation

@A-Moiz
Copy link

@A-Moiz A-Moiz commented Jan 25, 2026

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

Completed all the exercises in Sprint 2 directory

Questions

N/A

@A-Moiz A-Moiz added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 25, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Code is generally good.


// =============> write your new code here
function capitalise(str) {
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

For a variable not needed to be reassigned a value, a better practice is to use const instead of let.

Comment on lines +48 to +56
console.assert(formatAs12HourClock("01:00") === "01:00 am");
console.assert(formatAs12HourClock("11:59") === "11:59 am");

// Noon
console.assert(formatAs12HourClock("12:00") === "12:00 pm");
console.assert(formatAs12HourClock("12:30") === "12:30 pm");

// Afternoon / evening
console.assert(formatAs12HourClock("13:00") === "1:00 pm");
Copy link
Contributor

Choose a reason for hiding this comment

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

Output on lines 56 and 48 have slightly different format.
Can you modify the function to return a string in a consistent format?

Copy link
Author

Choose a reason for hiding this comment

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

Hi I'm unsure of the question you're asking. Line 56 tests if 13:00 is same as 1:00pm and line 48 tests if 01:00 is same as 01:00 am. All the assertions are passing currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

If "01:00" is converted to "01:00 am", it is reasonable for the caller to expect "13:00" to be converted to "01:00 pm".

What could go wrong? Here are two examples,

  • When the strings are all centered within a table column on a webpage, "01:00 pm" and "1:00 pm" would not align as nicely.
01:00 am
1:00 pm
12:00 am
01:00 pm
  • When the times are compared in the program, "1:00 pm" < "11:00 pm" and 01:00 pm" < "11:00 pm" produce different results.

Consistency is important so the caller can be certain what to expect from a function.

Did you choose the format "1:00 pm" by design (before you implement the function), or did you set the expected value in your tests because you knew that's what your function will return?

// Updated function:
function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
const minutes = time.slice(3, 5);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can also consider time.slice(-2) (a bit more expressive).

@cjyuan cjyuan 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 Feb 10, 2026
@A-Moiz A-Moiz 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 Feb 14, 2026
@cjyuan
Copy link
Contributor

cjyuan commented Feb 14, 2026

Changes look good.

Stretch exercise is optional so I will mark this PR as complete.

@cjyuan cjyuan 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 Feb 14, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants