-
-
Notifications
You must be signed in to change notification settings - Fork 387
London | 26-ITP-May | Dagim Daniel | Sprint 2 | key-errors #1411
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
Dagim-Daniel
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
Dagim-Daniel: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.
+113
−24
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1019333
Sprint 2 step 1 (key errors) all tasks under it has been done
Dagim-Daniel ef52ab7
Sprint 2 all tasks under mandatory-debug are done
Dagim-Daniel 784d465
Sprint 2 all tasks under mandatory-implement and mandatory- interpre…
Dagim-Daniel 9c0fba7
sprint 2 step 1 key errors convert to percentage - fix it to conve…
Dagim-Daniel 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,18 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // it will be reference error because the variable str is being declared twice, once as a parameter and once inside the function body. | ||
|
|
||
| // 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)}`; | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // the error is occurring because the variable str is being declared twice, once as a parameter and once inside the function body. | ||
| //removing the let keyword would fix this error, for the function to work properly. | ||
|
|
||
| // =============> write your new code here | ||
| let firstCapitalised = capitalise("hello"); | ||
| console.log(firstCapitalised); |
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,29 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // num is not defined at all, so when the function is called it will throw a reference error. | ||
| // and inside the function the parameter is not defined correctly, it should be num instead of 3. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| // reference error because the parameter is not defined correctly, it should be num instead of 3. | ||
| /* below is the original code | ||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| */ | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // the error was syntaxError: unexpected number. | ||
| // =============> explain this error message here | ||
|
|
||
| // because the parameter is not defined correctly, it should be num instead of 3. so the function is not defined correctly and it will throw a syntax error. | ||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function square(num) { | ||
| return num * num; | ||
|
|
||
| } | ||
| let result = square(3); | ||
| console.log(result); | ||
|
|
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,21 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| // there is no return statement in the multiply function, so when we try to log the result of the function call, it will return undefined. | ||
| /* original code | ||
| 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 | ||
|
|
||
| // console.log will do the multiplication of a and b and print the result to the console, but it will not return any value. | ||
| // there is no operation done here. just for testing purpose not actual operation. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| return a * b; // new code added to return the result of the multiplication. | ||
| } |
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,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| //we have to delete the semicolon used after the return statement in the sum function, because it will terminate the function and return undefined. | ||
| /* below is the original code | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| */ | ||
| // =============> write your explanation here | ||
| // same as my prediction. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; // removed the semicolon after the return statement to fix the problem. | ||
| // and also assigned the value of a + b to the return statement so that it will return the sum of a and b. | ||
| // unlike my prediction removing the semicolon only wont do the fix. because in javascript there is a feature called automatic semicolon insertion which will automatically insert a semicolon after the return statement | ||
| // when playing computer with this code it will read return with out ; as same as with it. - same error result | ||
| } | ||
|
|
||
| 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.
will this function work if you try with a different input?
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.
removing decimal = 0.5 ; makes it work for diffretnt inputs, should i change it and request new pull request?