From 8e69c6314114a21392a3694c1243c7b12532ff6c Mon Sep 17 00:00:00 2001 From: Michael Salvati Date: Sat, 24 Nov 2018 12:49:04 -0800 Subject: [PATCH] codiing challenge 1 completed --- 2-JS-basics/starter/index.html | 2 ++ 2-JS-basics/starter/main.js | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 2-JS-basics/starter/main.js diff --git a/2-JS-basics/starter/index.html b/2-JS-basics/starter/index.html index 975ef26c3b..3146f8359b 100755 --- a/2-JS-basics/starter/index.html +++ b/2-JS-basics/starter/index.html @@ -7,5 +7,7 @@

Section 2: JavaScript Language Basics

+ + \ No newline at end of file diff --git a/2-JS-basics/starter/main.js b/2-JS-basics/starter/main.js new file mode 100644 index 0000000000..de4007b977 --- /dev/null +++ b/2-JS-basics/starter/main.js @@ -0,0 +1,37 @@ +/***************************** +* CODING CHALLENGE 1 +*/ + +/* +Mark and John are trying to compare their BMI (Body Mass Index), which is calculated using the formula: BMI = mass / height^2 = mass / (height * height). (mass in kg and height in meter). + +1. Store Mark's and John's mass and height in variables +2. Calculate both their BMIs +3. Create a boolean variable containing information about whether Mark has a higher BMI than John. +4. Print a string to the console containing the variable from step 3. (Something like "Is Mark's BMI higher than John's? true"). + +GOOD LUCK 😀 +*/ + +let markValues = { + mass: 30, + height: 2.5 +} + +let johnValues = { + mass: 25, + height: 3 +} + +function whosBmiIsHigher(val1, val2){ + let markBmi = markValues.mass / Math.pow(markValues.height, 2); + let johnBmi = johnValues.mass / Math.pow(johnValues.height, 2); + + if(markBmi > johnBmi){ + console.log("At " + markBmi + "kg, Mark has a higher Bmi than John at " + johnBmi + "kg"); + } else { + console.log("At " + johnBmi + "kg, John has a higher Bmi than John at " + markBmi + "kg"); + } +} + +whosBmiIsHigher(markValues, johnValues); \ No newline at end of file