-
-
Notifications
You must be signed in to change notification settings - Fork 261
London | 25-ITP-September | Ammad Ur Rehman | Sprint 2 | 03 Complete Sprint 2 Coursework #786
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
Changes from 11 commits
e1af344
1028541
f342a4c
01dccfc
4bf3376
c929c3c
eae3b79
f6354f0
38d97c2
543ba9d
75172a0
851893c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ function formatTimeDisplay(seconds) { | |
| return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
| } | ||
|
|
||
| const number = 61; | ||
| console.log(formatTimeDisplay(number)); | ||
|
|
||
| // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
| // to help you answer these questions | ||
|
|
||
|
|
@@ -19,16 +22,26 @@ function formatTimeDisplay(seconds) { | |
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
|
|
||
| // 3 times | ||
|
|
||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // 0 | ||
|
|
||
| // c) What is the return value of pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // 00 | ||
|
||
|
|
||
| // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| // 1 | ||
|
|
||
| // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| // 01 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,18 @@ | |
| // 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`; | ||
| let hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(3, 5); | ||
|
||
|
|
||
| if (hours === 24) { | ||
| hours = 0; | ||
| } | ||
| return `${time} am`; | ||
|
|
||
| const period = hours < 12 ? "am" : "pm"; | ||
| hours = hours % 12 || 12; | ||
| const paddedHours = String(hours).padStart(2, "0"); | ||
|
|
||
| return `${paddedHours}:${minutes} ${period}`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
|
|
@@ -23,3 +30,31 @@ console.assert( | |
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("00:00"); | ||
| const targetOutput3 = "12:00 am"; | ||
| console.assert( | ||
| currentOutput3 === targetOutput3, | ||
| `current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
| ); | ||
|
|
||
| const currentOutput4 = formatAs12HourClock("24:00"); | ||
| const targetOutput4 = "12:00 am"; | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock("12:00"); | ||
| const targetOutput5 = "12:00 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); | ||
|
|
||
| const currentOutput6 = formatAs12HourClock("09:41"); | ||
| const targetOutput6 = "09:41 am"; | ||
| console.assert( | ||
| currentOutput6 === targetOutput6, | ||
| `current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.