Cape Town | 2026-ITP-Jan | Pretty Taruvinga | Sprint 2 | Structuring And Testing Data #1007
Cape Town | 2026-ITP-Jan | Pretty Taruvinga | Sprint 2 | Structuring And Testing Data #1007Pretty548 wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
2. Turned the code 3. Declared the function
This comment has been minimized.
This comment has been minimized.
4 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work, just one function you could improve a bit further
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| const bmi = weight / (height * height); | ||
| return Math.round(bmi * 10) / 10; |
There was a problem hiding this comment.
Why do you multiply by 10 and then divide by 10? Is there an easier way to get 1 decimal place?
There was a problem hiding this comment.
I multiplied by 10 and divided by 10 to round the BMI to one decimal place using Math.round(), since it only rounds whole numbers.
Alternatively, I could use Number(bmi.toFixed(1)) which is a bit cleaner and more readable.
There was a problem hiding this comment.
Good suggestion - I think toFixed makes more sense here. Can you make that change in the code?
There was a problem hiding this comment.
Thanks for the feedback! I've updated the function to use toFixed(1) for rounding to one decimal place.
Learners, PR Template
Self checklist
Changelist
In this sprint I worked on JavaScript challenges focused on functions, arrays, and string manipulation. I wrote pure functions that return values so they can be tested and used unit tests to confirm my solutions work correctly.
I practiced key concepts like variable scope, avoiding variable shadowing, and using methods such as padStart for formatting. One issue I faced was redeclaring a variable inside a function, which I fixed by using the parameter instead.
This sprint improved my problem-solving skills and my confidence in debugging and writing cleaner, more readable code.