generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 2 | Structuring and Testing Data #1125
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
Richiealx
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
Richiealx: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
17 commits
Select commit
Hold shift + click to select a range
f33028b
Sprint 2 errors: explain 0.js redeclaration error
Richiealx 4e7c018
Sprint 2 errors: explain 1.js redeclaration and scope error
Richiealx 25a5763
Sprint 2 errors: explain and correct 2.js invalid parameter error
Richiealx d2582ca
Sprint 2 debug: fix 0.js return vs console.log issue
Richiealx 29a57ec
Sprint 2 debug: fix 0.js return value issue
Richiealx b9fcbcc
Sprint 2 errors: refine answers formatting
Richiealx 4360d58
Sprint 2 debug: fix 1.js return statement
Richiealx 58789cd
Sprint 2 debug: fix 2.js parameter scope issue
Richiealx e795cdd
Sprint 2 implement: add calculateBMI function
Richiealx d1865f3
Sprint 2 implement: add UPPER_SNAKE_CASE function
Richiealx cb75590
Sprint 2 implement: add toPounds reusable function
Richiealx 4136e27
Sprint 2 implement: add reusable toPounds function
Richiealx 400e5a8
Sprint 2 interpret: complete time-format reasoning
Richiealx 5026ab3
Sprint 2 extend: add edge case tests and fix 12-hour clock conversion
Richiealx f9b067e
Sprint 2 errors: fix key errors 0-2 and document causes
Richiealx 27a5872
Fix BMI function to return number with 1 decimal place
Richiealx e9feff8
Fix indentation and formatting using Prettier
Richiealx 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
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... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // SyntaxError: Unexpected number | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| // function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
| // SyntaxError: Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| // The function parameter is written as 3, which is a number literal. | ||
| // Function parameters must be variable names (identifiers). | ||
| // JavaScript does not allow numbers as parameter names, | ||
| // so it throws a SyntaxError before running the program. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
| console.log(square(3)); | ||
|
|
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 |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Sprint 2 - 1 Key Errors (Answers) | ||
|
|
||
| ## 0.js | ||
| - Predicted error: | ||
| - Actual error: | ||
| - Why it happens: | ||
| - Minimal fix: | ||
| - Docs: | ||
|
|
||
| ## 1.js | ||
| - Predicted error: | ||
| - Actual error: | ||
| - Why it happens: | ||
| - Minimal fix: | ||
| - Docs: | ||
|
|
||
| ## 2.js | ||
| - Predicted error: | ||
| - Actual error: | ||
| - Why it happens: | ||
| - Minimal fix: | ||
|
|
||
|
|
||
|
|
||
| ## 0.js | ||
|
|
||
| - Predicted error: SyntaxError (variable redeclaration) | ||
|
|
||
| - Actual error: SyntaxError: Identifier 'str' has already been declared | ||
|
|
||
| - Why it happens: | ||
| The function parameter `str` is already declared. Inside the function, `let str = ...` attempts to redeclare the same variable in the same scope. JavaScript does not allow redeclaration of variables using `let`. | ||
|
|
||
| - Minimal fix: | ||
| Remove the `let` and return the new string directly: | ||
|
|
||
| ```js | ||
| function capitalise(str) { | ||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| } | ||
|
|
||
| - Docs: | ||
| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let | ||
|
|
||
|
|
||
|
|
||
| ## 1.js | ||
| - Predicted error: SyntaxError (variable redeclaration) | ||
|
|
||
| - Actual error: SyntaxError: Identifier 'decimalNumber' has already been declared | ||
|
|
||
| - Why it happens: | ||
| The function parameter `decimalNumber` is already declared. Inside the function, `const decimalNumber = 0.5;` attempts to redeclare the same variable in the same scope. JavaScript does not allow redeclaration using `const`. | ||
|
|
||
| There is also a second issue: | ||
| `console.log(decimalNumber);` is outside the function, and `decimalNumber` is not defined in the global scope. This would cause a ReferenceError. | ||
|
|
||
| - Concepts tested: | ||
| Variable scope, function parameters, redeclaration rules, global vs local variables. | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.5)); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| ## 2.js | ||
|
|
||
| - Predicted error: SyntaxError (invalid function parameter) | ||
|
|
||
| - Actual error: SyntaxError: Unexpected number | ||
|
|
||
| - Why it happens: | ||
| The function is declared as `function square(3)`. | ||
| Function parameters must be variable names (identifiers), not literal values. | ||
| The number `3` is not a valid parameter name, so JavaScript throws a syntax error. | ||
|
|
||
| - Concept tested: | ||
| Function declaration syntax and valid parameter identifiers. | ||
|
|
||
| - Minimal fix: | ||
|
|
||
| ```js | ||
| function square(number) { | ||
| return number * number; | ||
| } | ||
|
|
||
| console.log(square(3)); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
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,29 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // The function will print 320 from inside multiply, | ||
| // but the final console.log will show "undefined" | ||
| // because multiply does not return a 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 | ||
| // The function multiply only logs the result using console.log, | ||
| // but it does not return the value. | ||
| // Since it does not return anything, JavaScript returns undefined by default. | ||
| // Therefore, the template string inserts undefined. | ||
|
|
||
| // 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)}`); | ||
|
|
||
|
|
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 | ||
| // The function will return undefined because the return statement | ||
| // is followed by a line break. JavaScript inserts a semicolon automatically, | ||
| // so the function exits before a + b is executed. | ||
|
|
||
| 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 return statement is on its own line. | ||
| // JavaScript automatically inserts a semicolon after return. | ||
| // This means the function returns undefined immediately, | ||
| // and the expression a + b is never executed. | ||
|
|
||
| // 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
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.
Uh oh!
There was an error while loading. Please reload this page.