challenge #3

Udemy Jonas.io Javascript Fundamentals 2

by trentHarlem

HTML

<h2>
 Coding Challenge #3
</h2>

<p>
Let's go back to Mark and John comparing their BMIs! This time, let's use objects to implement the calculations! Remember: BMI = mass / height ** 2 = mass / (height * height). (mass in kg and height in meter)
</p>

<p>
1. For each of them, create an object with properties for their full name, mass, and height (Mark Miller and John Smith)<br>
2. Create a 'calcBMI' method on each object to calculate the BMI (the same method on both objects). Store the BMI value to a property, and also return it from the method.<br>
3. Log to the console who has the higher BMI, together with the full name and the respective BMI. Example: "John Smith's BMI (28.3) is higher than Mark Miller's (23.9)!"
</p>


TEST DATA: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall.<br>

GOOD LUCK 😀

CSS

html {
  font: 1.1em system-ui;
}

JavaScript

const john = {
  fullName: 'John Smith',
  mass: 92,
  height: 1.95,
  calcBMI: function() {
    let bmi = this.mass / this.height ** 2
    this.BMI = bmi
    return bmi
  }
}

const mark = {
  fullName: 'Mark Miller',
  mass: 78,
  height: 1.69,
  calcBMI: function() {
    let bmi = this.mass / this.height ** 2
    this.BMI = bmi
    return bmi
  }
}

mark.calcBMI();
john.calcBMI();

(john.BMI > mark.BMI) ?
console.log(`${john.fullName}'s BMI(${john.BMI}) is higher than ${mark.fullName}'s (${mark.BMI})`):
 console.log(`${mark.fullName}'s BMI(${mark.BMI}) is higher than ${john.fullName}'s (${john.BMI})`)