Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zelihapala
Copy link

@zelihapala zelihapala commented Nov 24, 2023

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@zelihapala zelihapala closed this Nov 24, 2023
@zelihapala zelihapala changed the title NW-6 | Zeliha Ellek | JS1| [TECH ED] Complete week 2 exercises | WEEK-2 NW-6 | Zeliha Pala | JS1| [TECH ED] Complete week 2 exercises | WEEK-2 Nov 24, 2023
@zelihapala zelihapala reopened this Nov 24, 2023

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)}`);

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. 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

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.)

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.

Copy link
Author

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;
}

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}`;
}

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.

Copy link

@HadikaMalik HadikaMalik left a 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. 👍

@zelihapala
Copy link
Author

Thank you for yor comments. They encouraged me.

Copy link
Contributor

@pseudopilot pseudopilot left a 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.

Comment on lines +22 to +25
function capitalise(str) {
Str = `${str[0].toUpperCase()}${str.slice(1)}`;
return Str;
}
Copy link
Contributor

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)}`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants