Skip to content

London | 26-ITP-SEPT | Carol Nassuna | Sprint 1 | Exhaustively test and fix formatAs12HourClock - #1657

Open
Mugs3 wants to merge 1 commit into
CodeYourFuture:mainfrom
Mugs3:Sprint-1
Open

Mugs3 wants to merge 1 commit into
CodeYourFuture:mainfrom
Mugs3:Sprint-1

Conversation

@Mugs3

@Mugs3 Mugs3 commented Oct 6, 2026

Copy link
Copy Markdown

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

Task code

CYF-1197

Changelist

Updated the 2 files

@Mugs3 Mugs3 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 2026

@abdishakoor-dev abdishakoor-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You kept both starter tests exactly as they were, and your midnight test is doing its job: it fails, because the function still has a bug there. That's exactly what a test is for.

How to run your tests. You'll need this for every step below:

  1. In VS Code, look at the file list on the left (the Explorer).
  2. Right-click the folder called format-clock-edge-cases and choose Open in Integrated Terminal. A terminal panel opens at the bottom of the screen.
  3. Click in that terminal panel, type node --test timeConverter.test.js and press Enter.
  4. Each test is listed with a ✔ (passed) or a ✖ (failed). At the bottom you'll see pass and fail with a number next to each.

At the moment you'll see pass 8 and fail 1. The ✖ is next to "can correctly convert midnight".

What to change before I can mark this Complete:

  1. Fix midnight in timeConverter.js, lines 5 and 6. My comment on line 5 explains how.

  2. Fix the typo in timeConverter.test.js line 30. My comment there explains it.

  3. Add three more tests at the bottom of timeConverter.test.js, after line 39. Copy one of your existing tests and change the time and the expected answer:

    • "00:30": half past midnight
    • "11:59": the last minute before am turns into pm
    • "13:00": one o'clock in the afternoon

    Work out what each should give on a 12-hour clock first, and write that as the expected answer.

  4. Delete lines 16 to 20 of timeConverter.js (the five console.log lines).

When you've made the changes, run node --test timeConverter.test.js in the terminal again. Push only when it says fail 0. Then add the Needs Review label again. Once these four are done, I expect to mark this Complete.


if (hours > 12) {
return `${hours - 12}:00 pm`;
if (time == "00") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is why the midnight test fails.

Line 5 checks whether time is "00". But for midnight, time is the whole text "00:00", so the check is never true, and the code carries on down to line 12, which returns "00:00 am".

Line 2 already gives you the hour on its own, as a number, in the variable hours. Change line 5 so it checks hours instead of time. Remember hours is a number, so compare it with a number, not with text in quotes.

Then look at line 6. It returns 12:00: followed by the minutes, which gives 12:00:00 am, one part too many. Line 10 is how you did it for noon. Midnight needs the same shape, but with am instead of pm.

Run node --test timeConverter.test.js in the terminal again. The midnight test should now show ✔.

});

test("can correctly convert time at the beginning of noon", function () {
assert.equal(formatAs12HourClock("12:001"), "12:01 pm");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's an extra 1 here: "12:001" should be "12:01". Delete the extra 1 so the test checks a real time. (It passes at the moment only by luck, because the function looks at the last two characters.)

}

export {formatAs12HourClock};
console.log(formatAs12HourClock("23:00"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These five lines were useful while you were working it out, but they print every time the tests run: you can see 11:00 pm, 2:00 pm and so on above your test results. Delete lines 16 to 20, then run node --test timeConverter.test.js again to check nothing else changed.

@abdishakoor-dev abdishakoor-dev 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 Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants