-
-
Notifications
You must be signed in to change notification settings - Fork 389
Manchester | 26-ITP-May | Szidonia Bodo | Sprint 2 | Coursework #1438
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
9fede25
a03c919
d0520a0
8e51dec
a72a8d2
0443b0b
75f7994
1b215b8
629157a
5ee1594
b970084
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,4 +1,6 @@ | ||
| // Predict and explain first... | ||
| //function is there to multiply the given arguments in the console log line 10 | ||
|
|
||
|
|
||
| // =============> write your prediction here | ||
|
|
||
|
|
@@ -9,6 +11,11 @@ function multiply(a, b) { | |
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // we would have an error message as we would need to return the statement | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| //function multiply(a, b) { | ||
| //return(a * b); | ||
|
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. Do you need to include these brackets here?
Author
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. No brackets are needed: |
||
| //} | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // the function will sum the given parameters | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // unable to return nothing - the statement is not given - has to be in the same line with the return | ||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| // function sum(a, b) { | ||
| //return a + b; | ||
| //} |
|
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. Good work - nice implementation of the pad function. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,58 @@ | ||
| // This is the latest solution to the problem from the prep. | ||
| // Make sure to do the prep before you do the coursework | ||
| // 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 pad(num) { | ||
| let numString = num.toString(); | ||
| while (numString.length < 2) { | ||
| numString = "0" + numString; | ||
| } | ||
| return numString; | ||
| } | ||
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const minutes = time.slice(3, 5); | ||
| if (hours === 0) { | ||
| return `12:${minutes} am`; | ||
| } else if (hours > 12) { | ||
| return `${pad(hours - 12)}:${minutes} pm`; | ||
| } else if (hours === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
| return `${pad(hours)}:${minutes} am`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| const currentOutput = formatAs12HourClock("06:00"); | ||
| const targetOutput = "06:00 am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| ); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| const currentOutput2 = formatAs12HourClock("12:00"); | ||
| const targetOutput2 = "12:00 pm"; | ||
| 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("22:59"); | ||
| const targetOutput4 = "10:59 pm"; | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock("21:30"); | ||
| const targetOutput5 = "09:30 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you try to run this test, does it work correctly?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct answer will be
function convertToPercentage(decimalNumber) {
const percentage =
${decimalNumber * 100}%;return percentage;
}
console.log(convertToPercentage(0.45));
we shouldn't declare the decimal number inside the function - as it was already declared as a parameter