generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 330
Sheffield | 26-Jan-ITP | Daniel Aderibigbe | Sprint 2 | coursework/sprint-2 #1049
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
Dan2Clouted
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
Dan2Clouted: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.
+198
−42
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0224852
key errors completed
Dan2Clouted 5729ef6
key errors completed
Dan2Clouted 442dbc8
test update
Dan2Clouted 9a4536d
test update
Dan2Clouted 9bfb891
completed all tasks in sprint 2
Dan2Clouted 4c33bc3
Merge branch 'main' into coursework/sprint-2
Dan2Clouted e21bdb3
updated changes based on reviewers feedback
Dan2Clouted 2eabe8c
Merge branch 'coursework/sprint-2' of https://github.com/Dan2Clouted/…
Dan2Clouted 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,26 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // The code will throw an error because the variable "str" is being declared twice 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; | ||
| } | ||
| //Original code with errors: | ||
|
|
||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // =============> write your explanation here | ||
| // The error occurs because the variable "str" is being declared twice in the same scope. This causes a conflict and results in a syntax error. | ||
| // To fix this error, we can simply remove the "let" keyword when reassigning the value to "str" inside the function. This way we are not declaring a new variable, but rather reassigning the existing parameter "str". | ||
|
|
||
| // =============> write your new code here | ||
| // Updated Code: | ||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| console.log(capitalise("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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // The code will throw an error because of an unexpected number "3" in the function parameter. The function parameter must be a variable name, not a number. | ||
| // Also, there is no num parameter declared in the function, so even if the function definition worked, it would sill cause a reference error when trying to use "num" in the return statement. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| //function square(3) { | ||
| // return num * num; | ||
| //} | ||
|
|
||
| // =============> write the error message here | ||
| // SyntaxError: Unexpected number in function parameter list. This error occurs because "3" is not a valid parameter name. Parameters should be variable names that can be used within the function body. | ||
| //ReferenceError: num is not defined. This error occurs because "num" is being used in the return statement, but it has not been declared or defined anywhere in the function. | ||
|
|
||
| // =============> explain this error message here | ||
| // To fix this error, we need to change the function parameter from "3" to a valid variable name, such as "num". This way, we can pass a number as an argument when calling the function, and it will be used correctly within the function body to calculate the square of that number. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); // output: 9 |
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,22 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // The code will throw an error message because multiply only logged the result and didnt return it. So when we try to use the result of multiply(10, 32) in the template literal, it will be undefined, which will cause an error when trying to perform string interpolation with an undefined value. | ||
|
|
||
| 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 | ||
| // To fix this error, we need to change the multiply function to return the result of the multiplication instead of just logging it. This way, when we call multiply(10, 32) inside the template literal, it will return the correct value (320) that can be used in the string interpolation without causing an error. | ||
|
|
||
| // 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,22 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // The code will throw an error message because the function "sum" has a return statement that is not returning any value. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| //function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| //} | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| //console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The function "sum" is not returning any value. | ||
| // To fix the error, we need to change the return statement to return the result of the addition of "a" and "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
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.
I could not find the definition of the function in this file.