generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 336
Birmingham | 26-ITP-Jan | Arun Kumar Akilan | Sprint 2 | Structuring-and-Testing-Data Coursework/Sprint2 #1117
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
arunkumarakilan
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
arunkumarakilan: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
7 commits
Select commit
Hold shift + click to select a range
ab3d116
Sprint 2: complete coursework tasks
arunkumarakilan 76d0588
Avoid mutating function parameter
arunkumarakilan ff2c4c5
Rename variable for clarity
arunkumarakilan f98c27d
Improve variable naming and use const
arunkumarakilan 52a1b76
Remove unnecessary parentheses in multiply function
arunkumarakilan 5cf8a5a
Refactor upperSnakeCase using method chaining
arunkumarakilan 0422ff0
Avoid mutating time parameter and store converted hours in a new vari…
arunkumarakilan 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,44 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // The code has a syntax error because a number is used instead of a parameter name in the function definition. | ||
| // Additionally, num is used inside the function without being declared or passed as an argument, which causes a ReferenceError. | ||
| // If the function is not called, it will not execute. | ||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| // The code has a syntax error because a number is used instead of a parameter name in the function definition. | ||
| // Additionally, num is used inside the function without being declared or passed as an argument, which causes a ReferenceError. | ||
| // If the function is not called, it will not execute. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // =============> write the error message here | ||
| // syntax error :unexpected number. | ||
|
|
||
| // =============> explain this error message here | ||
| // The error occurs because a number is used in the function definition instead of a parameter name. A function definition must contain a parameter (a variable name), not a value. | ||
|
|
||
| // Inside the function, num is used but it was never declared or passed as a parameter, which causes a ReferenceError because num is not defined in the scope. | ||
|
|
||
| // Also, if the function is not called, it will not execute. | ||
arunkumarakilan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // I corrected the function by properly defining num as a parameter instead of using a number in the function definition. This resolved the syntax error. | ||
|
|
||
| // Inside the function, num is now defined, so the ReferenceError is fixed. | ||
|
|
||
| // I then called the function with an argument and stored the returned value in a variable named num. Although the same variable name is used, the function parameter and the outer variable exist in different scopes, so there is no conflict. | ||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| const squaredValue = square(3); | ||
| console.log(squaredValue); | ||
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,39 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // The function multiplies the numbers and prints the answer. | ||
|
|
||
| // But it does not return the answer. | ||
|
|
||
| // Because there is no return, the function automatically gives back undefined. | ||
|
|
||
| // So when we use the function inside the second console.log, the value 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 | ||
| // console.log and return are not the same. | ||
|
|
||
| // console.log only prints the value to the console. | ||
|
|
||
| // It does not send the value back to the function call. | ||
|
|
||
| // Because there was no return statement, the function automatically returned undefined. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // To fix the issue, I replaced console.log with return. | ||
|
|
||
| // By returning a * b, the function now sends the calculated value back to where it was called. | ||
|
|
||
| // As a result, the correct value is displayed instead of undefined. | ||
| // =============> 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
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
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.