West-Midlands | 26-ITP-May | Maryam Janjua | Sprint 2 | Sprint 2 Coursework#1523
West-Midlands | 26-ITP-May | Maryam Janjua | Sprint 2 | Sprint 2 Coursework#1523maryam-devio wants to merge 14 commits into
Conversation
| console.log(decimalNumber); | ||
| console.log(decimalNumber);*/ | ||
|
|
||
| function convertToPercentage(decimalNumber) { |
There was a problem hiding this comment.
Good catch. However, please review the function's output, it seems to be returning the same result for every input.
There was a problem hiding this comment.
Thanks for the feedback! I have corrected the issue by removing the reassignment of the function parameter. The function now uses the argument passed to it, so it returns the correct percentage for different input values.
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| const squareHeight = height * height; | ||
| const div = weight / height; |
There was a problem hiding this comment.
Please review the BMI calculation formula in the instructions above again.
There was a problem hiding this comment.
Thanks for pointing that out! Oops, my bad—I mistakenly divided by the height instead of the squared height. I've corrected the BMI calculation to use the proper formula. Thanks for catching that!
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
|
||
| function SnakeUpperCase(str){ |
There was a problem hiding this comment.
The logic looks good, but the function name could be more descriptive. Also, you don't need to loop over every character in the string before calling replaceAll(), since it already replaces all occurrences.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
There was a problem hiding this comment.
Thank you for pointing that out! I understand that the loop was unnecessary since replaceAll() already replaces all occurrences in a single call. I've removed the loop and updated the function name to be more descriptive. Thanks for the helpful feedback!
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| function ConversionPenceToPounds(penceString){ |
There was a problem hiding this comment.
Good job turning the code into a reusable function. A few things to improve:
- The function name could be more concise and descriptive, please review the instruction.
paddedPenceNumberStringandpoundsshould be declared withconstorletto avoid creating global variables.- There is duplicated code where
paddedPenceNumberStringandpoundsare assigned twice. - Consider testing a few more edge cases, such as
"1p"or"100p".
There was a problem hiding this comment.
Thanks for the feedback! I've updated the function name to toPounds, declared paddedPenceNumberString and pounds with const, removed the duplicated assignments, and added tests for the suggested edge cases, including 1p and 100p (as well as a few others). Thanks for the helpful suggestions!
| `current output: ${currentOutput5}, target output: ${targetOutput}` | ||
| ); | ||
|
|
||
| const currentOutput5 = formatAs12HourClock(":00"); |
There was a problem hiding this comment.
there is a duplicate variable declaration that will cause the tests to fail before running.
|
@maryam-devio have you pushed your changes? I don't see the updated code. |
Learners, PR Template
Self checklist
Changelist
In this coursework, I completed the JavaScript exercises for Sprint 2. I practiced writing reusable functions, testing different inputs and edge cases, debugging code, and using built-in string methods. These exercises helped me improve my understanding of functions, loops, conditionals, and problem-solving in JavaScript.