London | 26-ITP-May | Eyob Zeray | Sprint 2 | Course Work - #1546
London | 26-ITP-May | Eyob Zeray | Sprint 2 | Course Work#1546eyob-tech wants to merge 1 commit into
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Good start, one small comment in a file to check
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| const bmi = weight / (height * height); | ||
| return Math.round(bmi * 10) / 10; |
There was a problem hiding this comment.
Is there a better choice than multiplying and then dividing by the same number?
There was a problem hiding this comment.
Good point — yeah, toFixed() is simpler for this. Something like Number(bmi.toFixed(1)) would do the same job in one step instead of the multiply/round/divide trick. I'll keep it as is for this PR since it's already passing, but I'll use toFixed() for rounding in future exercises. Thanks for the tip!
|
Yes, dividing and multiplying in javascript is always tricky because of floats, so avoiding it wherever you can is a good idea. toFixed is a more targeted alternative that works well here. I'll mark this as complete now |
Learners, PR Template
Self checklist
Changelist
Completed Sprint 2 exercises: fixed key errors, debugged and corrected mandatory-debug tasks, implemented BMI/cases/to-pounds functions, and answered the interpretation questions for time-format.js.