-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Closed
Closed
Changes from 10 commits
Commits
Show all changes
12 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 1c6a4c4
fix: returned BMI as a number (not a string) + rounding to 1 decimal
Eugenie-A fb558c1
Completed format.time.js stretch exercise
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,
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.
I expected the function to return a number, not a string.
No, my function didn't return the type of value I was expecting it to, but rather it was returned as a string due to
.toFixed(1).I updated it to
return Number( (weight / (height * height)).toFixed(1) );- This keeps the rounding to 1 decimal place but converts back to a number.