generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 239
London | 25-ITP-September | Carlos Abreu | Sprint 2 | Coursework #860
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
carlosyabreu
wants to merge
25
commits into
CodeYourFuture:main
Choose a base branch
from
carlosyabreu: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.
+3,771
−19
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e1447e3
Increase by 1 the variable count
carlosyabreu f184b29
Assignment operator equal
carlosyabreu d88693e
2-initials.js first letters of the variables
carlosyabreu ad07e16
Directory and extension part of a file path
carlosyabreu fc159be
Explanation of 4-random.js file
carlosyabreu 92d1f33
Using comment to explain the information contain in the file, useful …
carlosyabreu 204a98d
Change keyword 'const' to 'let' to assign variable
carlosyabreu b9538b2
Variable must be declared first before it can be used
carlosyabreu 5b6a38f
Extracting the last 4 digits and display it
carlosyabreu 57e97e9
Change variable naming starting with letter instead of numbers
carlosyabreu 7e75245
Change function replaceAll arguments adding commas to separate its pa…
carlosyabreu a36e485
commit 2-time-format.js and 3-to-pounds.js
carlosyabreu 94b7128
Add alert and prompt function explanation
carlosyabreu 269ce23
Console.log and Console and property
carlosyabreu 4818ddd
Correct a function with let defined inside it
carlosyabreu 992f376
Change the local variable to be called from global scope
carlosyabreu 607ca58
Change a literal numerical value as parameter for a variable expect b…
carlosyabreu 79b52ed
Commit 0.js and 1.js files
carlosyabreu 6b17b68
Change the function to display the last digit correctly
carlosyabreu e29954a
Correct the BMI function and the necessary explanation
carlosyabreu 9577ac5
Change small letter into capital letter
carlosyabreu 2b746b1
Different display of pounds
carlosyabreu 886d971
Test of function at different scenarios
carlosyabreu d34a28d
Display time in usual format
carlosyabreu da83341
Delete Sprint-1 folder
carlosyabreu 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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // This code will throw an error: "SyntaxError: Identifier 'str' has already been declared". | ||
| // The reason is that the variable 'str' is declared twice — once as a function parameter | ||
| // and again with `let str` inside the function. You cannot redeclare a parameter variable | ||
| // using `let` or `const` in the same scope. | ||
|
|
||
| // 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 | ||
|
|
||
| // The error occurs because 'str' is already defined as a parameter to the function. | ||
| // Using 'let str' again inside the function tries to redeclare it, which is not allowed. | ||
| // We can fix this by either using a different variable name or by reassigning 'str' | ||
| // directly without redeclaring it. | ||
|
|
||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| // Example: | ||
| 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... | ||
| // The console will print: | ||
| // 320 | ||
| // The result of multiplying 10 and 32 is undefined | ||
|
|
||
| // =============> write your prediction here | ||
| // The first `console.log` inside the function prints the multiplication result (320). | ||
| // However, since `multiply()` does not return anything, the outer `console.log` | ||
| // receives `undefined` as the value of the function call, leading to the message | ||
| // "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 | ||
|
|
||
| // The first `console.log` inside the function prints the multiplication result (320). | ||
| // However, since `multiply()` does not return anything, the outer `console.log` | ||
| // receives `undefined` as the value of the function call, leading to the message | ||
| // "The result of multiplying 10 and 32 is undefined". | ||
| // | ||
| // To fix this, the function should `return` the result instead of just logging it. | ||
| // 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)}`); | ||
| // Output: "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,33 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // The console will print: "The sum of 10 and 32 is undefined" | ||
| // This happens because the `return` statement ends the function immediately, | ||
| // so the expression `a + b` after it is never executed. | ||
| // As a result, the function returns `undefined`. | ||
|
|
||
| /** | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| */ | ||
|
|
||
| // =============> write your explanation here | ||
| // In JavaScript, when the interpreter encounters a `return` statement, | ||
| // it stops executing the rest of the function and immediately exits. | ||
| // Since there’s nothing after `return` on the same line, | ||
| // the function effectively returns `undefined`. | ||
| // The expression `a + b` is never reached due to JavaScript’s automatic semicolon insertion. | ||
|
|
||
| // 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)}`); | ||
| // Output: "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
Oops, something went wrong.
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.
What return value do you expect from the following function call?
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.
If the function toUpperSnakeCase() converts a string to UPPER_SNAKE_CASE then:
Because the function doesn't require the multiple white space to normalise (i.e. to collapse into one) then we might get multiple underscores resulting in the following output:
"HELLO___THERE"
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.
Does your function return
"HELLO___THERE"when the parameter is"hello there"?