generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | 26-ITP-Jan | Mahammad Osman| Sprint 2 | Coursework #1206
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
Darkidd77
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
Darkidd77:coursework/sprint-2
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
11 commits
Select commit
Hold shift + click to select a range
b573634
Fix variable declaration error in capitalise function
Darkidd77 598232d
convertToPercentage function
Darkidd77 e3b695c
Fix function definition to use a parameter instead of a direct input
Darkidd77 471439c
Fix function implementations to return correct values in multiply, su…
Darkidd77 14672ec
Implement BMI calculation in calculateBMI function
Darkidd77 6f0c4c8
Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE…
Darkidd77 4896b8f
Add defensive programming to toPounds function for input validation
Darkidd77 7d51222
Add console log and comments to clarify pad function usage in formatT…
Darkidd77 b507572
Refactor formatAs12HourClock function to correctly convert 24-hour ti…
Darkidd77 ae5326c
Fix: Passed num as a parameter inside getLastDigit
Darkidd77 db6a842
Fix: Remove unnecessary blank lines and ensure consistent formatting …
Darkidd77 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
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,20 +1,33 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // I think this is an obvious one because when defining a function you cant give a direct input like 3, | ||
| // instead you have to give a variable name as a parameter and then use that variable name in the function | ||
| // body to perform the calculation. So I predict that there will be a syntax error because of the way | ||
| // the function is defined with a direct input of 3 instead of a variable name. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| // function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
| // /Users/me/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:12 | ||
| // function square(3) { | ||
| // ^ | ||
|
|
||
| // SyntaxError: Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| // This error message is saying that there is an unexpected number in the function definition, which is the number 3. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
| console.log(square(3)); |
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... | ||
|
|
||
| // =============> write your prediction here | ||
| // I predict that there will be error because the function will not return anything | ||
| // and when we try to log the result of the function call to the console, it will return undefined. | ||
|
|
||
| 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 | ||
| // The function multiply logs in the result of a * b to the console but does not return anything, | ||
| // so when we try to log the result of the function call to the console, it will return 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,24 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I predict there will be a syntax error but not sure what the error is yet. | ||
| // I think it has something to do with return as it return nothing , so the function was'nt well defined. | ||
|
|
||
| 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 function sum is not returning the result of a + b, instead it is returning undefined | ||
| // because the return statement is on a separate line and does not include the expression a + b. | ||
|
|
||
| // 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 |
|---|---|---|
|
|
@@ -3,11 +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`; | ||
| let hours = Number(time.slice(0, 2)); // if its const it will throe an TypeError you cant assign a const variable later on | ||
| const minutes = time.slice(3, 5); | ||
|
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. We could also extract the last two characters as
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. I see, yes it's a better way. Thank you |
||
|
|
||
|
|
||
| // for am and pm periods | ||
| const period = hours >= 12 ? "pm" : "am"; // if hours is greater than or equal to 12, it's pm, otherwise it's am | ||
|
|
||
| // to convert hours from 24-hour format to 12-hour format | ||
| if (hours === 0) { | ||
| hours = 12; // if hours is 0, it should be 12 in 12-hour format | ||
| } else if (hours > 12) { | ||
| hours = hours - 12; | ||
| } | ||
| return `${time} am`; | ||
|
|
||
| // for format hours to always be 2 digits | ||
| const padHours = hours.toString().padStart(2, "0"); | ||
|
|
||
| return `${padHours}:${minutes} ${period}`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
|
|
@@ -23,3 +36,24 @@ console.assert( | |
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("12:00"); | ||
| const targetOutput3 = "12:00 pm"; | ||
| console.assert( | ||
| currentOutput3 === targetOutput3, | ||
| `current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
| ); | ||
|
|
||
| const currentOutput4 = formatAs12HourClock("00:00"); | ||
| const targetOutput4 = "12:00 am"; | ||
| console.assert( | ||
| currentOutput4 === targetOutput4, | ||
| `current output: ${currentOutput4}, target output: ${targetOutput4}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock("13:20"); | ||
| const targetOutput5 = "01:20 pm"; | ||
| console.assert( | ||
| currentOutput5 === targetOutput5, | ||
| `current output: ${currentOutput5}, target output: ${targetOutput5}` | ||
| ); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.