-
-
Notifications
You must be signed in to change notification settings - Fork 195
London | ITP-May-2025 | Seddiq Azam | Module-Structuring-and-Testing-Data | Sprint-1 #517
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
base: main
Are you sure you want to change the base?
Conversation
Detailed answer to questions
Co-authored-by: Copilot <[email protected]>
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.
Explanation is clear. Well done.
I only have a challenge question for you.
// 5. const pence = paddedPenceNumberString | ||
// .substring(paddedPenceNumberString.length - 2) | ||
// .padEnd(2, "0"); | ||
// This line extracts the last two digits, which represent the pence. | ||
// The `.padEnd(2, "0")` ensures that even if the pence value is only one digit (e.g., "5"), it becomes two digits (e.g., "05"). | ||
// So "5p" would correctly display as "£0.05" instead of "£0.5". |
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.
Could we expect this program to work as intended for any valid penceString
if we deleted .padEnd(2, "0")
from the code?
In other words, do we really need .padEnd(2, "0")
in this script?
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.
.padEnd(2, "0") ensures that the pence value always has two digits, by padding with a zero on the right if necessary.
if we remove .padEnd(2, "0"), the value "5p" will be displayed as "£0.5"
.substring(paddedPenceNumberString.length - 2) will return just "5" when the input is only one digit long.
This leads to incorrect currency formatting, since "£0.5" means 50p, not 5p.
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.
Have you tried verifying your expectations by executing the script without .padEnd(2, "0")
using different values of penceString
?
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 tested the code with different values. When I used "999p", the output was "£9.99" — both with and without .padEnd(2, "0").
After doing some research, I found that the line:
.substring(paddedPenceNumberString.length - 2)
returns the last two characters of the string. In this case, it correctly returns "99", which is already two characters long.
Therefore, using .padEnd(2, "0") is unnecessary in this situation.
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.
Pull Request Overview
This PR adds detailed documentation and explanatory comments across several modules while fixing minor errors in variable declarations and string methods. Key changes include expanded answers on JavaScript console behavior and user prompts, improved inline explanations for number formatting and error debugging, and corrections to variable declarations in error examples.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
Sprint-1/4-stretch-explore/objects.md | Added step-by-step answers about the Chrome DevTools Console. |
Sprint-1/4-stretch-explore/chrome.md | Expanded the walkthrough and explanation of prompting in Chrome. |
Sprint-1/3-mandatory-interpret/3-to-pounds.js | Detailed commentary on handling currency string formatting. |
Sprint-1/3-mandatory-interpret/2-time-format.js | Extended answers regarding time formatting with suggestions. |
Sprint-1/3-mandatory-interpret/1-percentage-change.js | Added explanations and highlighted a syntax error fix in replaceAll. |
Sprint-1/2-mandatory-errors/(1.js, 2.js, 3.js, 4.js) | Fixed variable declaration issues and corrected method calls. |
Sprint-1/1-key-exercises/(1-count.js, 2-initials.js, 3-paths.js, 4-random.js) | Included detailed answers and updated code examples for clarity. |
// This code will not display properly for movies with a duration of 0 seconds, | ||
// as the output would appear as "0:0:0", which is not well-formatted. | ||
|
||
// We can fix this by applying the .padStart() method to each time unit |
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.
Consider updating the code to apply padStart for formatting hours, minutes, and seconds. This will ensure that values like '0' are displayed as '00', improving the readability of the time output.
Copilot uses AI. Check for mistakes.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
This pull request concerns the sprint-1 tasks for the module.
Implemented various functions to generate random integers within a specified range, minimum, and maximum.
used Math.random() scaled to the range size, with Math.floor() to ensure an integer results.
identified common errors in the code
Questions
Ask any questions you have for your reviewer.