Coding Challenge #1,2
Udemy Complete Javascript Course 2021
by trentHarlem
HTML
<h2>
Coding Challenge #1 / #2
</h2>
<p>
Mark and John are trying to compare their BMI (Body Mass Index), which is calculated using the formula:<br> BMI = mass / height ** 2 = mass / (height * height).<br> (mass in kg and height in meter).</p>
<p>1. Store Mark's and John's mass and height in variables<br>
2. Calculate both their BMIs using the formula (you can even implement both versions)<br>
3. Create a boolean variable 'markHigherBMI' containing information about whether Mark has a higher BMI than John.</p>
TEST DATA 1: <br> Mark weights 78 kg and is 1.69 m tall.<br> John weights 92 kg and is 1.95 m tall.<br>
TEST DATA 2:<br> Mark weights 95 kg and is 1.88 m tall.<br> John weights 85 kg and is 1.76 m tall.
GOOD LUCK 😀
CSS
html {
font: 18px system-ui;
}
JavaScript
// EXAMPLE Does Not inculde a Function on purpose.
// test data 1
let markMass = 78;
let markHeight = 1.69
let johnMass = 92;
let johnHeight = 1.95
let markBMI = markMass / markHeight**2
let johnBMI = johnMass / johnHeight**2
const markHigherBMI = markBMI > johnBMI
console.log(markBMI, johnBMI, markHigherBMI)
if (markBMI > johnBMI) {
console.log(`Mark's BMI, (${markBMI}) is higher than John's (${johnBMI})!`)
} else {
console.log("John's BMI is higher than Marrk's!")
}
/* // test data 2
let markMass2 = 95;
let markHeight2 = 1.88
let johnMass2 = 85;
let johnHeight2 = 1.76
let markBmi2 = markMass2 / markHeight2**2
let johnBmi2 = johnMass2 / johnHeight2**2
const markHigherBMI2 = markBmi2>johnBmi2
console.log(markBmi2,johnBmi2, markHigherBMI2) */