Skip to content

Instantly share code, notes, and snippets.

@kironroy
Created May 3, 2023 20:10
Show Gist options
  • Save kironroy/1a6a2e2418a9f4495c7c294ab5e1ff92 to your computer and use it in GitHub Desktop.
Save kironroy/1a6a2e2418a9f4495c7c294ab5e1ff92 to your computer and use it in GitHub Desktop.
JavaScript
const johnObj = {
firstName: 'John',
lastName: 'Smith',
mass: 78,
height: 1.69,
calcBMI: function () {
this.bmi = (this.mass / this.height);
return this.bmi;
},
getSummary: function() {
return `${this.firstName} ${this.lastName} has a BMI of ${this.calcBMI()}.`
}
}
// console.log(johnObj.getSummary());
const markObj = {
firstName: 'Mark',
lastName: 'Miller',
mass: 95,
height: 1.88,
calcBMI: function () {
this.bmi = (this.mass / this.height);
return this.bmi;
},
getSummary: function() {
return `${this.firstName} ${this.lastName} has a BMI of ${this.calcBMI()}.`
}
}
// console.log(markObj.getSummary());
// console.log(`${johnObj.firstName} ${johnObj.lastName} is ${johnObj.calcBMI()} `);
if (johnObj.calcBMI() > markObj.calcBMI()) {
console.log(` ${johnObj.firstName} ${johnObj.lastName}
has a BMI of ${johnObj.calcBMI()}
which is more than ${markObj.firstName}'s which is: ${markObj.calcBMI()}`);
} else if(markObj.calcBMI() > johnObj.calcBMI()) {
console.log(` ${markObj.firstName} ${markObj.lastName}
has a BMI of ${markObj.calcBMI()}
which is more than ${johnObj.firstName}'s which is: ${johnObj.calcBMI()}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment