generated from CodeYourFuture/Module-Template
-
-
Couldn't load subscription status.
- Fork 239
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 2 | Coursework Sprint 2 #778
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
Iswanna
wants to merge
21
commits into
CodeYourFuture:main
Choose a base branch
from
Iswanna: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
21 commits
Select commit
Hold shift + click to select a range
60f2cf6
Add some lines of code to calculate the area of a rectangle
Iswanna 909a41e
Add function to capitalize first letter of a name
Iswanna 6b42d00
Compare the current output with the target output using the strict eq…
Iswanna 4470330
Organize prep directory into sprint-1 and sprint-2 folders and move J…
Iswanna 86552fe
Use the console.assert function in the code
Iswanna 1f028f7
Define a function to convert argument to time with "am" and add basse…
Iswanna 7993291
Predict the output of the provided function, explain the actual error…
Iswanna aca4398
Explain why the program throws an error, simulate execution to identi…
Iswanna a8d716b
Add code predictions, explanations, and corrections
Iswanna b509c65
Change the first letter in ActualOutput to lower case
Iswanna f08d00a
Predict program behavior and provide corrected code
Iswanna f4b2ba4
Improve phrasing in the prediction section for clarity
Iswanna 09df5e9
Predict what the sum function will output, explain how the code works…
Iswanna b639581
Comment out the lines of code with the error
Iswanna f59d4fc
Explain each line of the multiply function
Iswanna ebaaadc
Predict and explain each function call’s output, then fix the code to…
Iswanna 97e074f
Updatea function that takes two parameters to calculate the BMI
Iswanna 49b8d14
Write a function that takes a string argument and converts it to UPP…
Iswanna 183ee2d
Refactor program into a reusable function
Iswanna 2a3fc95
Add answers to questions about pad and formatTimeDisplay functions
Iswanna a74b44e
Remove prep folder as it’s not related to this branch
Iswanna 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 | ||
| // Answer | ||
| // If I call the function capitalise with a string input, I predict that it will return an error because the variable str | ||
| // has already been declared as a paramter of the function so it can not be re-declared | ||
|
|
||
| // 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 | ||
| //Answer | ||
| // The error message "SyntaxError: Identifier 'str' has already been declared" means that the identifier "str" has been declared and so can not be re-declared. | ||
| // This error occured because the same variable name occurs as a function parameter and is then redeclared using a let assignment in a function body again. | ||
| // Redeclaring the same variable within the same function or block scope using let is not allowed in JavaScript. | ||
|
|
||
| // =============> write your new code here | ||
| // Answer | ||
| 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 | ||
| let actualOutput = capitalise("welcome"); | ||
| console.log(actualOutput); |
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,37 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // Answer | ||
| // If this program runs, I predict that the function will return undefined because it has no return statement. | ||
| // Also, the console.log inside the multiply function will print its output to the terminal. | ||
| // Lastly, because the function returns undefined, when ${multiply(10, 32)} is used inside a template literal inside the console.log function, it will print undefined in that position. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
| //function multiply(a, b) { | ||
| //console.log(a * b); | ||
| //} | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // Explanation | ||
| // function multiply(a, b) {} | ||
| // This expression defines a function named multiply. | ||
| // The function takes two parameters: a and b. | ||
|
|
||
| // console.log(a * b); | ||
| // This expression multipies a and b and prints the result in the terminal. | ||
| // There is no return statement, so the function implicitly returns undefined. | ||
|
|
||
| // console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| // In this expression, multiply(10, 32) is called. | ||
| // Because the function returns undefined, the template literal becomes: "The result of multiplying 10 and 32 is undefined" | ||
| // That string is printed to the console. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| console.log(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,46 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // Answer | ||
| // I predict that calling sum(10, 32) will return `undefined`. | ||
| // This is because the `return` statement has a semicolon immediately after it, | ||
| // so JavaScript interprets it as `return;` which evaluate to "undefined" when the function is called | ||
| // The expression `a + b` on the next line will never be executed. | ||
| // Therefore, any console.log using sum(10, 32) will display `undefined` in the output. | ||
|
|
||
| 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 | ||
| // Explanation | ||
| // function sum(a, b) { | ||
| // This declares a function named sum that takes two parameters: a and b. | ||
|
|
||
| // return; | ||
| // The return statement is immediately followed by a semicolon. | ||
| // This causes the function to exit immediately. | ||
| // Since nothing is returned explicitly, JavaScript returns undefined by default. | ||
|
|
||
| // a + b; | ||
| // This line never executes because the function has already exited at the `return;` line. | ||
|
|
||
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // In this expression, sum(10, 32) is called. | ||
| // Because the function returns undefined, the template literal becomes: "The sum of 10 and 32 is undefined" | ||
| // That string is printed to the console. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // I will fix the error by placing the expression a + b on the same line as the return statement. | ||
| // Optionally, I can use parentheses around the expression, but this is not required. | ||
|
|
||
| // =============> 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The code in the function is not properly indented.
This VSCode feature might interest you:
https://code.visualstudio.com/docs/languages/javascript#_formatting