Northwest | May-2025 | Sofayas Solomon | Sprint 2 #658
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.
Learners, PR Template
Self checklist
Changelist
This pull request covers all Sprint-2 prep exercises, including the following main tasks:
Errors
Reviewed multiple error files in the errors directory
Predicted the errors before running the code
Interpreted the error messages and explained why they occur
Gained experience debugging common JavaScript errors like syntax errors and variable redeclarations
Debug
Analyzed several buggy programs in the debug folder
Predicted why each program did not behave as intended
Ran and verified these predictions in Node.js
Corrected the code to fix bugs such as wrong function parameters and missing returns
Implement
Built functions based on specific requirements:
Calculated BMI with calculateBMI(weight, height)
Converted strings to UPPER_SNAKE_CASE
Created a reusable toPounds function
Tested these functions against multiple input cases to ensure correctness
Interpret
Read and interpreted larger code examples with unfamiliar syntax or functions
Used MDN and other documentation to understand JavaScript methods and behaviors
Employed console.log for variable inspection and debugging
Extend
Extended the 24-hour to 12-hour clock conversion function (formatAs12HourClock)
Wrote multiple tests covering groups of inputs and edge cases (e.g., "00:00", "12:00", "13:00", times with minutes)
Fixed bugs found during testing to make the function robust and accurate
Questions
In the section where we refactor the formatAs12HourClock function, I understand why we create a variable for the hours to avoid repetition. But how do I decide when it’s important to refactor like this in larger programs? Are there best practices or guidelines to know when and how often to refactor for readability and performance?