Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format-time exercise #41

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
24 changes: 24 additions & 0 deletions Sprint-2/extend/format-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This is the latest solution to the problem from the prep.
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
Copy link
Member

Choose a reason for hiding this comment

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

Fun fact: this is exactly how my 7 year old niece does this calculation

}
return `${time} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);

const currentOutput2 = formatAs12HourClock("23:00");
const targetOutput2 = "11:00 pm";
console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);
5 changes: 5 additions & 0 deletions Sprint-2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ Here is a recommended order:
In these tasks, you have to interpret a slightly larger program with some syntax / operators / functions that may be unfamiliar.
You must use documentation to make sense of anything unfamiliar - learning how to look things up this way is a fundamental part of being a developer!
SallyMcGrath marked this conversation as resolved.
Show resolved Hide resolved
You can also use `console.log` to check the value of different variables in the code.

## Extend

In the prep for this sprint, we developed a function to convert 24 hour clock times to 12 hour clock times.
Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.