-
-
Notifications
You must be signed in to change notification settings - Fork 379
London | 26-ITP-May | Khaliun Baatarkhuu | Sprint 2 | Coursework #1355
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
khaliun-dev
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
khaliun-dev: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
13 commits
Select commit
Hold shift + click to select a range
44df68b
Fix duplicate declaration error in capitalise function
khaliun-dev e767704
Fix variable clash and update function usage
khaliun-dev 452f037
Correct square function parameter and logic
khaliun-dev d8cf3ad
Fix multiply function to return the result
khaliun-dev a6357b6
Fix sum function to return the correct sum
khaliun-dev 96ce70f
Fix getLastDigit function to accept input parameter
khaliun-dev b9ffdc1
Implement BMI calculation function
khaliun-dev 902b0b9
Add function to convert string to upper snake case
khaliun-dev e75086b
Add toPounds function for currency conversion
khaliun-dev 2dc5eb1
Document answers for pad function questions
khaliun-dev 5ae68a9
Fix time formatting for 12-hour clock
khaliun-dev d8e4f7f
Fix 12 PM formatting in time conversion function
khaliun-dev c168e89
Correct time format in formatAs12HourClock function
khaliun-dev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,43 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============> just like in the previous exercise, you can't have two variables | ||
| //with the same name in one scope. Second error is you can't call on "decimalNumber" | ||
| //from outside the function. Since that variable only lives inside the function. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| //a parameter (decimalNumber) is created | ||
| const decimalNumber = 0.5; | ||
| //this is where the first error appears, as now there are two clashing variables | ||
| //under the same name. Code stops working. | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> my prediction was correct. | ||
|
|
||
| // 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(0.5)); | ||
|
|
||
| //removed the clashing variable and placed the function call inside the | ||
| //console log. | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
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,14 +1,31 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> this code needs a return function to insert 320 into the string | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> this code creates a function called multiply on line 5, line 6 is ignored for now because it's part of the function definition. | ||
| //Then JS read the code further from top to bottom until line 9, where it sees the values attached to the parameters and runs the function on 5 now, with new values. | ||
| //lines 6 then becomes console.log(320). Function ends here. | ||
|
|
||
| // | ||
|
|
||
| // 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 exercise is about understanding the differemce between console and return , in essense. | ||
| With return, the value can be inserted into the template literal. | ||
| With console.log, the value is only displayed and then discarded. | ||
|
|
||
| */ |
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,20 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // =============> due to the semicolon on line 5 , the function will not progress further. In the console line template literal becomes | ||
| //`The sum of 10 and 32 is ${undefined}` | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> my prediction was correct, i have removed the semicolon and put the expression on line 6 with the return function on line 5. | ||
|
|
||
| // 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 |
|---|---|---|
|
|
@@ -23,3 +23,64 @@ console.assert( | |
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
|
|
||
| // i am runnign the following tests, since morning and afternoon times were done already, | ||
| // noon, different minutes. | ||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| /* | ||
| Since we know what the bug is, i shall handle it as a special case, and add the following code. | ||
|
|
||
| if (hours === 12) { | ||
| return `${time} pm`; | ||
| } | ||
|
|
||
| Tested it again and it works now. | ||
| */ | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| } | ||
| return `${time} am`; | ||
| } | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("12:00"); | ||
| const targetOutput3 = "12:00 pm"; | ||
| console.assert(currentOutput3 === targetOutput3); | ||
|
|
||
| console.log(formatAs12HourClock("12:00")); | ||
|
|
||
| //i have run this code in dev tools , the asnwer was 12:00am , bug found. | ||
|
|
||
|
|
||
|
|
||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(3); | ||
|
|
||
| if (hours === 12) { | ||
| return `${time} pm`; | ||
| } | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
| } | ||
|
|
||
| const currentOutput3 = formatAs12HourClock("12:00"); | ||
| const targetOutput3 = "12:00 pm"; | ||
| console.assert(currentOutput3 === targetOutput3); | ||
|
|
||
| console.log(formatAs12HourClock("15:29")); | ||
|
|
||
|
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. Now that you have found the bugs, do you know what would be needed to fix them?
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. Thanks for reviewing my code. I have fixed both bugs. Cheers. |
||
| //Answer was 3:00pm, bug found. | ||
|
|
||
| //PS: fixed the bug by adding a seperate variable for minutes. Tested it again and it works now. | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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.
BMI has lots of limitations as a measuring system, so don't worry about it too much :)