-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
NW-6 | Zeliha Pala | JS1| [TECH ED] Complete week 2 exercises | WEEK-2 #165
base: main
Are you sure you want to change the base?
Conversation
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
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.
You have explained this very well here. I understand what you wrote and did. 👍
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.
Thank you
week-2/implement/bmi.js
Outdated
function calculateBMI(weight, height) { | ||
const bmi = weight / (height * height); | ||
return parseFloat(bmi.toFixed(1)); | ||
// Round to 1 decimal place (parseFloat(bmi.toFixed(1)) takes the calculated BMI, rounds it to one decimal place as a string, and then converts it back to a floating-point number, ensuring that the BMI returned by the function has only one decimal place. This helps keep the BMI value precise to the specified decimal point.) |
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 you explain why you used parseFloat here? I have not used it and that is why I am wondering what parseFloat would do.
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.
Thank you for your review @HadikaMalik
parseFloat() is a used to parse (or convert) a string into a floating-point number.
it is used to ensure that the result of toFixed(1) (which rounds the BMI to one decimal place and returns it as a string) is converted back into a floating-point number.
For instance, if toFixed(1) returns "24.5" (as a string), using parseFloat("24.5") will convert it to the number 24.5.
|
||
return upperCamelCase; | ||
} | ||
|
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 you explain what .split on line 23 and .map on line 26 does? I want to understand thhis better to know what you were doing.
const pence = num.slice(-2); | ||
return `£${pounds}.${pence}`; | ||
} | ||
|
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.
This code is so neat and easily understandable.
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.
Really nice written code.There are some parts which I did not understand properly, I hope you can explain them to me so that I can know better. But overall your code is written nicely and can be easily followed and understood. 👍
Thank you for yor comments. They encouraged me. |
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.
@zelihapala , awesome job!
I only left one comment. Please, check it.
function capitalise(str) { | ||
Str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return Str; | ||
} |
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.
Your explanation is correct here 👍
But I think your implementation may be improved.
Firstly, in JS we have a convention to use camelCasedNames
, it means your new variable name should start with lowercased latter. Your suggestion t use modifiedStr
is perfect for this purpose!
Secondly, if you introduce a new variable, you should use either let
or const
in the beginning.
Thirdly, just str =
${str[0].toUpperCase()}${str.slice(1)}`` (without let in front of it) should work too. As all the function arguments (like str
here) may be changed as any variable declared with `let`.
But we should be careful with this approach, because after changing initial value of `str` we won't be able to refer to initial value any more.
Fourthly, you may even avoid creating variables her and just:
return `${str[0].toUpperCase()}${str.slice(1)}`;
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.