diff --git a/index.html b/index.html index 975ef26..3a077e6 100644 --- a/index.html +++ b/index.html @@ -7,5 +7,6 @@

Section 2: JavaScript Language Basics

+ - \ No newline at end of file + diff --git a/script.js b/script.js new file mode 100644 index 0000000..42aa0e7 --- /dev/null +++ b/script.js @@ -0,0 +1,34 @@ +const john = { + fullName: 'John Smith', + mass: 70, + height: 1.7, + + calcBIM() { + return this.BMI = this.mass / Math.pow(this.height, 2); + } +}; + +const mark = { + fullName: 'Mark Doe', + mass: 50, + height: 1.5 +}; + +const winner = {}; + +mark.calcBIM = john.calcBIM; +john['BMI'] = john.calcBIM(); +mark['BMI'] = mark.calcBIM(); + +if (john.BMI > mark.BMI) { + winner['name'] = 'John'; + winner['BMI'] = john.BMI; +} +else if (mark.BMI > john.BMI) { + winner['name'] = 'Mark'; + winner['BMI'] = mark.BMI; +} + +highestBMI = john.BMI !== mark.BMI ? `${winner.name} has the highest BMI of ${winner.BMI}` : 'Both have the same BMI'; + +console.log(highestBMI);