Skip to content
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2dd0a78
explain Increment count variable by 1 after initialization.
HoussamLh Jun 17, 2025
1bc5c74
Create initials variable by extracting first characters of first, mid…
HoussamLh Jun 17, 2025
b16d048
create two variable and Extract directory and file extension parts fr…
HoussamLh Jun 17, 2025
625c114
Add comments explaining how num is calculated as a random integer bet…
HoussamLh Jun 17, 2025
f5522e7
Add explanation for incrementing count variable by 1 after initializa…
HoussamLh Jun 17, 2025
1cf3f70
I believe that I've Done the sprint 1 and this the last exercise.
HoussamLh Jul 6, 2025
b76c5a3
I believe that I've completed the first sprint.
HoussamLh Jul 6, 2025
0748f7c
I've changed const to let for age variable to allow reassignment
HoussamLh Jul 13, 2025
d957dd1
Avoid redeclaring 'str' inside capitalise function
HoussamLh Jul 13, 2025
fcba7aa
Remove redeclaration of parameter and undefined variable usage in con…
HoussamLh Jul 13, 2025
c278bbb
Use valid parameter name instead of number in square function
HoussamLh Jul 13, 2025
335cc37
Avoid redeclaring 'str' inside capitalise function
HoussamLh Jul 15, 2025
2f9d4da
Return value from multiply function instead of just logging it
HoussamLh Jul 15, 2025
bdc5ac9
Correct return statement in sum function to return a + b
HoussamLh Jul 15, 2025
16d6577
Update getLastDigit function to use input parameter instead of consta…
HoussamLh Jul 15, 2025
8796b5b
Implement calculateBMI function with 1 decimal rounding
HoussamLh Jul 15, 2025
1b5f2cf
Convert strings to UPPER_SNAKE_CASE format
HoussamLh Jul 15, 2025
6573f60
Create reusable toPounds function with test cases
HoussamLh Jul 15, 2025
01a1ced
Add inline comments explaining pad and formatTimeDisplay behaviour
HoussamLh Jul 15, 2025
eeff899
Correct 12-hour clock formatting and add comprehensive tests
HoussamLh Jul 15, 2025
f39781a
Revert Sprint-1 folder to CYF's original version
HoussamLh Jul 21, 2025
bce599b
Revert Sprint-1 folder to CYF's original version
HoussamLh Jul 21, 2025
19f296f
convert kg to pounds and round to 2 decimal places
HoussamLh Jul 21, 2025
f63026f
Create reusable toPounds function from Sprint-1 code
HoussamLh Jul 21, 2025
a9c2a21
format 12-hour time consistently with 2-digit hours
HoussamLh Jul 21, 2025
5eb1ab8
Refactor formatAs12HourClock to reduce code duplication
HoussamLh Jul 22, 2025
c229426
Merge branch 'CodeYourFuture:main' into acoursework/sprint-2
HoussamLh Sep 7, 2025
81ae2ac
Refactor capitalize function and simplify code
HoussamLh Sep 10, 2025
9b67749
Refactor convertToPercentage function and simplify code
HoussamLh Sep 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format 12-hour time consistently with 2-digit hours
  • Loading branch information
HoussamLh committed Jul 21, 2025
commit a9c2a215bed092c7c7cff0bbc007da68a050ddad
24 changes: 16 additions & 8 deletions Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
const minutes = time.slice(3, 5);

let formattedHour;
let period;

if (hours === 0) {
// midnight
return `12:${minutes} am`;
formattedHour = "12";
period = "am";
} else if (hours === 12) {
// noon
return `12:${minutes} pm`;
formattedHour = "12";
period = "pm";
} else if (hours > 12) {
return `${hours - 12}:${minutes} pm`;
formattedHour = String(hours - 12).padStart(2, "0");
period = "pm";
} else {
// 1am to 11am
return `${time} am`;
formattedHour = String(hours).padStart(2, "0");
period = "am";
}

return `${formattedHour}:${minutes} ${period}`;
}


// Tests:
const tests = [
{ input: "00:00", expected: "12:00 am" },
{ input: "08:00", expected: "08:00 am" },
{ input: "12:00", expected: "12:00 pm" },
{ input: "15:30", expected: "3:30 pm" },
{ input: "15:30", expected: "03:30 pm" },
{ input: "23:59", expected: "11:59 pm" },
{ input: "11:15", expected: "11:15 am" },
];
Expand All @@ -34,3 +41,4 @@ tests.forEach(({ input, expected }) => {
);
});