generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 259
Birmingham | 25-ITP-Sep | Baba Yusuf | Sprint 2 | Module-Structuring-and-Testing-Data #768
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
Closed
+3,571
−25
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c2ed214
checked npm install
Baba05206 9659871
Fix syntax errors and improve function implementations in key error e…
Baba05206 c09112f
Refactor functions to return values instead of logging; update explan…
Baba05206 5a7c70d
Implement BMI calculation and UPPER_SNAKE_CASE conversion functions; …
Baba05206 8913624
Add test cases for formatAs12HourClock function and document edge cas…
Baba05206 e6fd262
Correct answers for questions b) and c) in time-format.js comments
Baba05206 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,26 @@ | ||
|
|
||
| // 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 | ||
|
|
||
| /* | ||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| */ | ||
| // =============> write the error message here | ||
|
|
||
| // SyntaxError: Unexpected number | ||
| // =============> explain this error message here | ||
| /* | ||
| 1-The parameter name '3' is not a valid identifier. Function parameters names must (be valid variable names & not literal values), i.e. start with a letter, underscore (_), or dollar sign ($), and cannot be a number. | ||
| 2-Also, the function uses 'num' which is not defined anywhere. It should use the parameter name instead. | ||
| 3-Finally, the function is not called anywhere, so it won't produce any output. | ||
| */ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); // This line is inserted only to test the function. It returns 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,27 @@ | ||
| // Predict and explain first... | ||
|
|
||
| /* | ||
| The function 'multiply' does not return any value, it only logs the product of 'a' and 'b' to the console, within itself. | ||
| Therefore, when we try to use its result in a template literal, it will be 'undefined'. | ||
| In the below, i expect the TWO outputs to be, 320 and The result of multiplying 10 and 32 is undefined. | ||
| */ | ||
| // =============> write your prediction here | ||
|
|
||
| /* | ||
| 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 | ||
|
|
||
| /* | ||
| 1. I will change the function to return the product of 'a' and 'b' instead of logging it. | ||
| This way, when we call 'multiply(10, 32)', it will return 320, | ||
| which can then be used in the template literal. | ||
| */ | ||
| // 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,29 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // =============> write your prediction here | ||
| /* | ||
| The function 'sum' does not return the sum of 'a' and 'b' because there is a semicolon immediately after the 'return' statement. | ||
| This causes the function to return 'undefined' instead of the intended sum. | ||
| */ | ||
| /* | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| */ | ||
| // =============> write your explanation here | ||
| /* | ||
| 1. In JavaScript, when a 'return' statement is followed by a newline, it is treated as if there is a semicolon immediately after 'return'. | ||
| 2. This means that the function exits at the 'return' statement and does not execute the next line, which contains the actual sum operation. | ||
| 3. As a result, the function returns 'undefined' instead of the sum of 'a' and 'b'. | ||
| 4. To fix this, we need to place the expression to be returned on the same line as the 'return' statement. | ||
| */ | ||
| // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,25 +10,36 @@ function formatTimeDisplay(seconds) { | |
|
|
||
| return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
| } | ||
| console.log(formatTimeDisplay(61)); // This line is inserted only to test the function. It returns "00:01:01" | ||
|
|
||
| // Here is a function that takes a number of seconds and returns a string formatted as "HH:MM:SS" | ||
| // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
| // to help you answer these questions | ||
|
|
||
| // Questions | ||
|
|
||
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
|
|
||
| //3 times | ||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| //61 | ||
| // c) What is the return value of pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| //0 | ||
|
||
| // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| /* | ||
| The value assigned to num when pad is called for the last time is 1. | ||
| The last call to pad in the template literal is pad(remainingSeconds). Since remainingSeconds = 61 % 60 = 1, the value passed to num is 1. This will return "01" after padding, resulting in the final output "00:01:01" | ||
| */ | ||
| // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
| /* | ||
| The return value of the last call to pad is "01". | ||
| Explanation: When pad is called with remainingSeconds (which equals 1), the parameter num receives the value 1. The function then converts it to a string "1", | ||
| pads it to 2 characters with leading zeros to get "01", and returns this string. This returned value "01" | ||
| is then inserted into the template literal as the last part of the time display, producing the final output "00:01:01". | ||
| */ | ||
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.
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.
Are you sure this will be the first value? When is pad first called?