From 31c02239ad9d7998812fd3f430f1bfd0e84d340b Mon Sep 17 00:00:00 2001 From: jess2896 Date: Thu, 26 Sep 2019 12:38:46 -0400 Subject: [PATCH 1/2] Calculates who has the highest BMI out of two person objects --- index.html | 3 ++- script.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 script.js diff --git a/index.html b/index.html index 975ef26..955e354 100644 --- a/index.html +++ b/index.html @@ -8,4 +8,5 @@

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..30e9f88 --- /dev/null +++ b/script.js @@ -0,0 +1,24 @@ +let John = { + fullName : 'John Smith', + mass : 70, + height : 1.9, + calcBIM: function(){ + return this.BMI=this.mass/(this.height*this.height); + } +} + +let Mark = { + fullName : 'Mark Doe', + mass : 50, + height : 1.5, + calcBIM: function(){ + return this.BMI=this.mass/(this.height*this.height); + } +} +let highestBMI='John and Mark have the same BMI'; + +if(John.calcBIM()!==Mark.calcBIM()){ + highestBMI = John.BMI>Mark.BMI?John.fullName+" has the highest BMI of "+ John.BMI:Mark.fullName+" has the highest BMI of "+ Mark.BMI;; +} + +console.log(highestBMI); From ed48685e783811f8aa8074194636d985380545d9 Mon Sep 17 00:00:00 2001 From: jess2896 Date: Mon, 30 Sep 2019 11:35:30 -0400 Subject: [PATCH 2/2] Fixed the code's format --- index.html | 2 +- script.js | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 955e354..3a077e6 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,6 @@

Section 2: JavaScript Language Basics

+ - diff --git a/script.js b/script.js index 30e9f88..42aa0e7 100644 --- a/script.js +++ b/script.js @@ -1,24 +1,34 @@ -let John = { - fullName : 'John Smith', - mass : 70, - height : 1.9, - calcBIM: function(){ - return this.BMI=this.mass/(this.height*this.height); - } -} +const john = { + fullName: 'John Smith', + mass: 70, + height: 1.7, -let Mark = { - fullName : 'Mark Doe', - mass : 50, - height : 1.5, - calcBIM: function(){ - return this.BMI=this.mass/(this.height*this.height); + calcBIM() { + return this.BMI = this.mass / Math.pow(this.height, 2); } -} -let highestBMI='John and Mark have the same BMI'; +}; + +const mark = { + fullName: 'Mark Doe', + mass: 50, + height: 1.5 +}; -if(John.calcBIM()!==Mark.calcBIM()){ - highestBMI = John.BMI>Mark.BMI?John.fullName+" has the highest BMI of "+ John.BMI:Mark.fullName+" has the highest BMI of "+ Mark.BMI;; +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);