generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 302
London | 26-ITP-January | Eugenie Ahangama | Sprint 2 | coursework/sprint 2 #931
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
Eugenie-A
wants to merge
10
commits into
CodeYourFuture:main
Choose a base branch
from
Eugenie-A: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
10 commits
Select commit
Hold shift + click to select a range
f2a2aba
Fixed capitaliseStr function and confirmed output with test
Eugenie-A 8a3c7d2
Fixed convertToPercentage function by removing variable shadowing and…
Eugenie-A be9e3ec
Fixed square() parameter error, added MDN explanation and test cases
Eugenie-A 7a826d5
Fixed multiply() return issue and added MDN explanation
Eugenie-A 11c30c6
Fixed empty return in sum() and added explanation with MDN reference
Eugenie-A b2530bc
Fixed getLastDigit() to use parameter instead of hardcoded value and …
Eugenie-A 2ce418b
Added calculateBMI() implementation and test case using example value…
Eugenie-A 3cd9638
Implemented toUpperSnakeCase() function for converting strings to UPP…
Eugenie-A 2b518a5
Implemented toPounds() function to convert pence strings into pounds.…
Eugenie-A 22765cb
Broke down time formatting and understood pad() call behaviour
Eugenie-A 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 | ||
| // Prediction: The code will throw a SyntaxError because the variable 'str' has already been declared as a parameter of the function. | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| // Original code with error: | ||
|
|
||
| /* | ||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| */ | ||
|
|
||
| // =============> write your explanation here | ||
| // Explanation: The error occurs because the variable 'str' is being redeclared within the function using 'let', | ||
| // which is not allowed since 'str' is already declared as a parameter of the function. | ||
| // To fix this, we can either rename the inner variable or simply assign the new value to the existing parameter without redeclaring it. | ||
|
|
||
| // =============> write your new code here | ||
| // Fixed code: | ||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| console.log(capitalise("hello")); // Output: "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
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,35 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // Prediction: The function will not multiply the numbers. | ||
| // Instead, it will print the sum of a and b (42) and the final console.log will ouput: | ||
| // The result of multiplying 10 and 32 is undefined | ||
|
|
||
| /* Original code | ||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| */ | ||
|
|
||
| // =============> Error message | ||
| // 320 | ||
| // The result of multiplying 10 and 32 is undefined | ||
|
|
||
| // =============> write your explanation here | ||
| // MDN Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return | ||
|
|
||
| // The function multiply() uses console.log() to print the result but it does not return anything. | ||
| // In JavaScript, if a function does not explicitly return a value, it returns undefined. | ||
| // When we try to use multiplay(10, 32) inside a console.log, it returns undefined. | ||
| // To fix this, we must use the return statement so the function gives back a value that can be used. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
|
|
||
| // The result of multiplying 10 and 32 is 320 | ||
| 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,32 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // Prediction: The code should output - "The sum of 10 and 32 is 42" | ||
| // But the code will return undefined instead of 42. | ||
|
|
||
| /* Original code | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| */ | ||
|
|
||
| // =============> Error message | ||
| // The sum of 10 and 32 is undefined | ||
|
|
||
| // =============> write your explanation here | ||
| // MDN Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return | ||
|
|
||
| // The function uses `return;` without an expression. | ||
| // According to MDN, if a return statement has no value, the function returns undefined. | ||
| // So when `sum(10, 32)` is called, it returns undefined. | ||
| // To fix this, the return statement must 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
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.
What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,