This coding challenge focuses on JavaScript objects and methods. The objective was to create two objects, each representing a person, with properties including firstName
, lastName
, mass
, and height
. Additionally, a method named calcBMI
was to be implemented in each object to calculate the BMI (Body Mass Index) based on the provided formula. Finally, a comparison between the BMIs of the two individuals was to be logged to the console using a specific string format.
- Create two JavaScript objects, each representing a person, with properties:
firstName
lastName
mass
(in kilograms)height
(in meters)
- Implement a method named
calcBMI
within each object to calculate the BMI using the formula: BMI = mass / (height * height) - Use an if/else statement to compare the BMIs of the two individuals.
- Log a message to the console indicating whose BMI is higher, following the format: "{firstName} {lastName}'s BMI ({calculatedBMI}) is higher than {firstName} {lastName}'s BMI ({calculatedBMI})."
For example, if the calculated BMIs for two individuals were:
- John Miller: BMI = 24.5
- Mark Smith: BMI = 23.4 The output logged to the console should be: "John Miller's BMI (24.5) is higher than Mark Smith's BMI (23.4)."
-
Clone the repository to your local machine: git clone https://github.com/Olamiposi-cloud-coder/objectsChallenge.git
-
Open the index.js file and review the implementation of the objects and methods.
-
Run the code to see the comparison of BMIs logged to the console.
[Cloud] - [https://github.com/Olamiposi-cloud-coder]
Feel free to contribute to the project by providing feedback, suggestions, or improvements via pull requests.
Happy coding!