Created
May 3, 2023 20:57
-
-
Save kironroy/f84ea2acec42f8c52e6860fa8d8b18bc to your computer and use it in GitHub Desktop.
JavaScript Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const johnObj = { | |
fullName: 'John Smith', | |
mass: 92, | |
height: 1.95, | |
calcBMI: function () { | |
this.bmi = this.mass / this.height ** 2; | |
return this.bmi; | |
}, | |
getSummary: function() { | |
return `${this.firstName} ${this.lastName} has a BMI of ${this.calcBMI()}.` | |
} | |
} | |
// console.log(johnObj.getSummary()); | |
const markObj = { | |
fullName: 'Mark Miller', | |
mass: 78, | |
height: 1.69, | |
calcBMI: function () { | |
this.bmi = this.mass / this.height ** 2; | |
return this.bmi; | |
}, | |
getSummary: function() { | |
return `${this.firstName} ${this.lastName} has a BMI of ${this.calcBMI()}.` | |
} | |
} | |
// function calls | |
markObj.calcBMI() | |
johnObj.calcBMI() | |
if (markObj.bmi > johnObj.bmi) { | |
console.log(`${markObj.fullName} has a BMI of ${markObj.bmi} which higher than ${johnObj.fullName}'s BMI: ${johnObj.bmi}`); | |
} else if (johnObj.bmi > markObj.bmi) { | |
console.log(`${johnObj.fullName} has a BMI of ${johnObj.bmi} which is more than ${markObj.fullName}'s BMI: ${markObj.bmi} `); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment