generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 321
London | 26-ITP-January | Laura C | Sprint 2 | Structuring and Testing Data #960
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
lauracs24
wants to merge
12
commits into
CodeYourFuture:main
Choose a base branch
from
lauracs24:acoursework/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
12 commits
Select commit
Hold shift + click to select a range
bece12d
add prediction, explanation and corrected function for redeclaration …
lauracs24 47250f9
add prediction, explanation and corrected function for decimalNumber …
lauracs24 52d7af4
resolve Unexpected number SyntaxError in square function (2.js)
lauracs24 c1206f8
resolve undefined result by returning value in multiply function
lauracs24 2259714
explain and fix undefined result caused by misplaced return in sum fu…
lauracs24 268f2e1
explain and fix bug in getLastDigit (mandatory debug)
lauracs24 b28bccd
implement BMI calculation with 1 decimal rounding
lauracs24 dde33c9
implement string conversion to UPPER_SNAKE_CASE mandatory implement
lauracs24 4cb4a65
implement toPounds function to format pence strings
lauracs24 497ab63
answer interpret questions for formatTimeDisplay
lauracs24 b24523e
Clarify explanation about parameter and global scope in getLastDigit
lauracs24 578600f
Fix indentation and return type in calculateBMI function
lauracs24 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,35 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // I predict this will throw a SyntaxError because | ||
| // the variable 'str' is declared twice inside the function. | ||
|
|
||
|
|
||
|
|
||
| // 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; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // This code throws a SyntaxError: Identifier 'str' has already been declared. | ||
| // The function parameter is named 'str', and inside the function | ||
| // we try to declare another variable using 'let str'. | ||
| // JavaScript does not allow redeclaring a variable | ||
| // in the same scope. | ||
|
|
||
|
|
||
| // =============> write your new code here | ||
| function capitaliseFixed(str) { | ||
| let result = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return result; | ||
| } | ||
|
|
||
| console.log(capitaliseFixed("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
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,27 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I think this might print undefined | ||
| // The return statement looks separate from a + b, | ||
| // so maybe the function is not actually returning the sum. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
| //console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The function has 'return;' on its own line. | ||
| // When JavaScript sees return, it stops the function immediately. | ||
| // That means 'a + b' never runs. | ||
| // Because nothing is returned, the function returns undefined. | ||
|
|
||
| // 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.
It is possible to have a global variable and a parameter named
numin a script. For example,Can you find out why?
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.
Ah I think the issue was not the shared variable name, but that the function did not define a parameter. I have updated my explanation to reflect this
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.
Your change is good, and you are right about the function not having a parameter.
I meant to point out these two concepts, "identifier scope and identifier resolution, in the context of JavaScript programming". ChatGPT can give a good explanation.