London | 26-ITP-January | Damian Dunkley | Sprint 2 | coursework/sprint-2#1012
London | 26-ITP-January | Damian Dunkley | Sprint 2 | coursework/sprint-2#1012DamianDL wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
oyagbileoluwaseun
left a comment
There was a problem hiding this comment.
You can make the few adjustments, especially in 1-key-errors, and it would be better.
Sprint-2/1-key-errors/0.js
Outdated
| // The error is occurring because we are trying to declare a variable 'str' inside the function that has the same name as the parameter 'str'.To fix this problem, create an variable with a new name Newstr . So we would change the line to: Newstr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let Newstr = `${str[0].toUpperCase()}${str.slice(1)}`; |
There was a problem hiding this comment.
Hello Damian,
This is good work spotting the error, but do you know about the camelCase name convention? You can check that out to help improve your naming convention.
There was a problem hiding this comment.
Hi Oyagbile- thanks for the review and feedback. New variable name changed from Newstr to newStr, to conform to camelCase naming convention. Thanks
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNum = 0.5; |
There was a problem hiding this comment.
You successfully sorted the redeclaration error.
|
|
||
| // =============> write your new code here | ||
|
|
||
| function square(num) { |
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // The error is occurring because the function 'multiply' is not returning any value. In JavaScript, if a function does not explicitly return a value, it returns 'undefined' by default. To fix this problem, we need to add a return statement to the function that returns the result of multiplying 'a' and 'b'. For example, we could change the line to: return a * b; so that the function will return the correct result when called. |
Sprint-2/2-mandatory-debug/2.js
Outdated
|
|
||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // The function getLastDigit is not taking any parameters, so it always returns the last digit of the global variable 'num', which is 103. The function should take a number as a parameter and return the last digit of that number. |
There was a problem hiding this comment.
The function will ignore the arguments passed in and always return the last digit of the global variable num.
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| const bmi = weight / (height ^2); |
There was a problem hiding this comment.
Do you think this is the most optimised way to do an exponentiation?
If not leyt me know how you would fix it.
| penceString.length - 1 | ||
| ); | ||
|
|
||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); |
| @@ -10,6 +10,10 @@ function formatTimeDisplay(seconds) { | |||
|
|
|||
| return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | |||
| } | |||
…tr, to conform with camelCase naming
…taking global parameter only
…t an exponent in JS to heightxheight
…t an exponent in JS to Math.pow(height,2)
| // =============> write your explanation here | ||
| // The error is occurring because we are trying to declare a variable 'str' inside the function that has the same name as the parameter 'str'.To fix this problem, create an variable with a new name Newstr . So we would change the line to: Newstr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // =============> write your new code here | ||
| function capitalise(str) { |
|
|
||
| // =============> write your explanation here | ||
| // The error is occurring because we are trying to declare a variable 'str' inside the function that has the same name as the parameter 'str'.To fix this problem, create an variable with a new name Newstr . So we would change the line to: Newstr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // =============> write your new code here |
Learners, PR Template
Self checklist
Changelist
Completion of Sprint 2 exercises
Questions
Please review changes to exercises?