-
-
Notifications
You must be signed in to change notification settings - Fork 336
Manchester | ITP-Jan-26 | Ofonime Edak| Sprint 2 |Structuring and testing Data #1097
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
base: main
Are you sure you want to change the base?
Changes from all commits
200135d
74a3301
a9e0b1c
1942553
65c1eac
87fc640
ff49d6c
9d8f2ef
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 |
|---|---|---|
| @@ -1,20 +1,28 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| //This code is to take one number function parameter and return area. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> write your prediction of the error here. | ||
| // syntaxError: passing an argument instead for a parameter. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
| //SyntaxError:Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| //The function was not expecting number during declaration | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| //function square(num) { | ||
| // return num * num; | ||
| //} | ||
| //console.log(square(3)) |
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,24 @@ | |
| // 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`; | ||
| const hours = time.slice(0, 2); | ||
| const minutes = time.slice(3, 5); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (Number(hours) > 12) { | ||
| let timeHour = Number(hours) - 12; | ||
|
Comment on lines
+6
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not convert If you need also |
||
| if (timeHour.toString().length !== 2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also check |
||
| timeHour = timeHour.toString().padStart(2, "0"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| return `${timeHour}:${minutes} pm`; | ||
| } else if (Number(hours) === 0) { | ||
| return `12:${minutes} am`; | ||
| } else if (Number(hours) === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
| return `${hours}:${minutes} am`; | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| //Test cases | ||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| console.assert( | ||
|
|
@@ -23,3 +34,59 @@ 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 currentOutput5 = formatAs12HourClock("15:01"); | ||
| const targetOutput5 = "03:01 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); | ||
|
|
||
| const currentOutput6 = formatAs12HourClock("13:00"); | ||
| const targetOutput6 = "01:00 pm"; | ||
| console.assert( | ||
| currentOutput6 === targetOutput6, | ||
| `current output: ${currentOutput6}, target output: ${targetOutput6}` | ||
| ); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const currentOutput7 = formatAs12HourClock("12:00"); | ||
| const targetOutput7 = "12:00 pm"; | ||
| console.assert( | ||
| currentOutput7 === targetOutput7, | ||
| `current output: ${currentOutput7}, target output: ${targetOutput7}` | ||
| ); | ||
|
|
||
| const currentOutput8 = formatAs12HourClock("12:30"); | ||
| const targetOutput8 = "12:30 pm"; | ||
| console.assert( | ||
| currentOutput8 === targetOutput8, | ||
| `current output: ${currentOutput8}, target output: ${targetOutput8}` | ||
| ); | ||
|
|
||
| const currentOutput9 = formatAs12HourClock("11:59"); | ||
| const targetOutput9 = "11:59 am"; | ||
| console.assert( | ||
| currentOutput9 === targetOutput9, | ||
| `current output: ${currentOutput9}, target output: ${targetOutput9}` | ||
| ); | ||
|
|
||
| const currentOutput10 = formatAs12HourClock("12:01"); | ||
| const targetOutput10 = "12:01 pm"; | ||
| console.assert( | ||
| currentOutput10 === targetOutput10, | ||
| `current output: ${currentOutput10}, target output: ${targetOutput10}` | ||
| ); | ||
|
|
||
| const currentOutput11 = formatAs12HourClock("00:45"); | ||
| const targetOutput11 = "12:45 am"; | ||
| console.assert( | ||
| currentOutput11 === targetOutput11, | ||
| `current output: ${currentOutput11}, target output: ${targetOutput11}` | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.