generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 240
NW | 25-ITP-Sep | TzeMing Ho | Sprint 2 | coursework/sprint-2 #707
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
TzeMingHo
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
TzeMingHo: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
16 commits
Select commit
Hold shift + click to select a range
9d43b8b
npm installed
TzeMingHo 150a780
In 1 key-errors, made a preditions, explained the syntax error, and f…
TzeMingHo 8fdb210
In 1-key-errors, deleted unwanted variable, and console.log function …
TzeMingHo 24f2d3c
In 1-key-errors/2.js, replacing 3 with num as parameter
TzeMingHo 96ebf89
In 2-mandatory-debug/0.js, updated return in the function
TzeMingHo b2f87c5
In 2-mandatory-debug/1.js, updated return inline with a+b
TzeMingHo b73f73f
In 2-mandatory-debug/2.js, adding a parameter in the function
TzeMingHo 72112ca
In 3-mandatory-implement/1-bmi.js, filled in the function to get bmi …
TzeMingHo a505558
In 3-mandatory-implement/2-cases.js, created a function to convert lo…
TzeMingHo 6c1636f
In 3-mandatory-implement/3-to-pounds.js, created a reusable function …
TzeMingHo 401db2b
In 4-mandatory-interpret/time-format.js, filled in answers
TzeMingHo 5733d12
In 5-stretch-extend/format-time.js, tried edge cases and invalid inputs
TzeMingHo 096632e
correcting padStart for minutes String
TzeMingHo b0fe035
Remove package-lock.json from pull request
TzeMingHo 7a2b0a1
ignore package-lock.json
TzeMingHo b5b597c
restore gitignore from origin/main
TzeMingHo 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,29 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I guess the function is trying to capitalise the first letter of the string, | ||
| // capture the rest of the string from index 1 to the end of the string, | ||
| // and concatenate them together to return the capitalised string | ||
|
|
||
| // 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 | ||
| // After calling the function capitalise with a string input, | ||
| // I got a syntax error that "str" has already been declared. | ||
| // This is because str has already been declared as a parameter of the function, | ||
| // when a new variable named str, it causes a conflict. | ||
|
|
||
| // =============> write your new code here | ||
| // I renamed the new variable to capitalisedStr to avoid the conflict | ||
|
|
||
| function capitalise(str) { | ||
| let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return capitalisedStr; | ||
| } | ||
| console.log(capitalise("hello")); // should return "Hello" | ||
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,27 @@ | ||
|
|
||
| // 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 guess the error is a reference error because the parameter is not defined correctly. | ||
| /* | ||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| */ | ||
| // =============> write the error message here | ||
| // function square(3) { | ||
| // ^ | ||
| //SyntaxError: Unexpected number | ||
| // In fact, the error is a syntax error because number 3 is unexpected here. | ||
|
|
||
| // =============> explain this error message here | ||
| // Number 3 is not a valid parameter name, which is misplacing and causes a syntax error. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); // should return 9 |
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 | ||
|
|
||
| // It seems the function multiply did not return any value. | ||
| // Therefore, it is like a console.log returning undefined, while it is inside another console.log. | ||
| // So the output should be "The result of multiplying 10 and 32 is undefined". | ||
| /* | ||
| 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 | ||
| // After running the code, I got a separate output of 320 and "The result of multiplying 10 and 32 is undefined". | ||
| // This is because the function multiply does not return any value, so it returns undefined by default. | ||
| // The console.log inside the function multiply prints 320 when the function is called. | ||
|
|
||
| // 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)}`); // should return "The result of multiplying 10 and 32 is 320" |
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,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // It looks like the function sum return nothing because a+b is written in the next line after return statement. | ||
| // Therefore, the output should be "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 | ||
| // After running the code, I got "The sum of 10 and 32 is undefined". | ||
| // The return statement ends the function execution and a+b is never evaluated. | ||
|
|
||
| // 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)}`); // should return "The sum of 10 and 32 is 42" |
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
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.
This works as expected - but do we need a variable here?
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.
No. We could simply return
${str[0].toUpperCase()}${str.slice(1)}The variable is not necessarily needed.