-
-
Notifications
You must be signed in to change notification settings - Fork 546
Manchester | 26-ITP-Sep | Mathew Shaibu | Sprint 3 | Coursework/sprint-3 #1587
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
Open
MattCarolus10
wants to merge
14
commits into
CodeYourFuture:main
Choose a base branch
from
MattCarolus10:coursework/sprint-3-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db8bec9
Complete Sprint 3 coursework
MattCarolus10 af89dc0
simplified task o.js
MattCarolus10 f919f28
fix str function
MattCarolus10 a56fa7f
comments rephrased
MattCarolus10 7a68faf
format code using prettier
MattCarolus10 29644df
add semi-colons to lines
MattCarolus10 82f391f
time-format deleted all unwanted comment
MattCarolus10 da4a942
padStart used and deleted unwanted comments
MattCarolus10 6b0f9f4
padStart used and deleted unwanted comments
MattCarolus10 a1a3870
format.js
MattCarolus10 5e0afc9
format.js
MattCarolus10 cafd4e7
format.js
MattCarolus10 7c9837f
0.js task completed
MattCarolus10 20a688e
fix: correct return statement in capitalise function
MattCarolus10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,24 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // ======> write your prediction here: | ||
| // Answer below: | ||
|
|
||
| // I predict that the code should make the first letter of the string an uppercase letter, | ||
| // then add every letters that comes after | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here: | ||
| // Answer below: | ||
|
|
||
| // The error read "SyntaxError: Identifier 'str' has already been declared", | ||
| // This is as a result of having two variables with same name "str". | ||
| // The error occoured in this code because the variable "str" has been declared twice | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function capitalise(str) { | ||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| } | ||
| console.log(capitalise("money")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,38 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // Answer below: | ||
| // A syntax error will occur for two reasons, first because there variable const "decimalNumber" being redecleared | ||
| // The second reason is because the function "convertToPercentage" is not called correctly. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
| // =============> write your prediction here: | ||
| // Answer below: | ||
| // I predicted that the code will not work because of the variable (decimalNumber) inside the function, | ||
| // Also because the console.log(decimalNumber) is just a name that exist inside the function | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| // function convertToPercentage(decimalNumber) { | ||
| // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| console.log(decimalNumber); | ||
| // return percentage; | ||
| // } | ||
| // console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // Answer: | ||
|
|
||
| // const decimalNumber redeclares the parameter name which causes a SyntaxError. | ||
| // also console.log(decimalNumber) outside fails because the parameter only exists inside the function" | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| console.log(convertToPercentage(10.5)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,31 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // Answer below: | ||
| // The code will not work because the placeholder variable (3) should be an actual name like "num" | ||
|
|
||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| // function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
| // SyntaxError: Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| // The error message explains the error in the function parameter (3), the function expects a name parameter instead of a number. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(10)) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,24 @@ | ||
| // Predict and explain first... | ||
| // Answer below: | ||
| // The code needs a value inside the console.log function to multiply, but no value was useed to replace the placeholder parameters | ||
| // It should be an error, no value to return | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
| // function multiply(a, b) { | ||
| // console.log(a * b); | ||
| // } | ||
| // console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // Answer below: | ||
| // The original logs the product instead of returning it, so the function call inside the template string gives undefined | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function multiply(a, b) { | ||
| return a * b | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // Code will not work because the paremeters should be on same line as return | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The errors in this codes is the semi-colon in front of the return and the placeholder parameters not on same line as the return | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,44 @@ | ||
| // 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. | ||
|
|
||
|
|
||
| // Test result: | ||
| // Hours and Minutes worked in the AM function for different time test. | ||
| // 12:00 in the afternoon doesn't function correctly | ||
| // 00:00 mid-night doesn't work | ||
| // Minutes in the PM are not working. | ||
|
|
||
| // To fix bug: | ||
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(3, 5); | ||
|
|
||
| if (hours === 0) { | ||
| return `12:${minutes} am`; | ||
| } | ||
| if (hours === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; | ||
| } | ||
|
|
||
| return `${time} am`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| const currentOutput = formatAs12HourClock("01:00"); | ||
| const targetOutput = "01:00 am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| `current output: ${currentOutput}, target output: ${targetOutput}`, | ||
| ); | ||
| console.log(formatAs12HourClock("01:00")); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("19:30"); | ||
| const targetOutput2 = "07:30 pm"; | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}`, | ||
| ); | ||
|
|
||
| console.log(formatAs12HourClock("19:30")); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note: The .slice() method supports negative indices, which count positions from the end of the string.
For example,
str.slice(-3)returns the substring containing last three characters fromstr.