Skip to content

Commit 2a72f2e

Browse files
authored
Merge pull request #1 from 3daddict/dev
coding challenge 1 completed
2 parents 9782d9d + 8e69c63 commit 2a72f2e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

2-JS-basics/starter/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77

88
<body>
99
<h1>Section 2: JavaScript Language Basics</h1>
10+
11+
<script src="main.js"></script>
1012
</body>
1113
</html>

2-JS-basics/starter/main.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*****************************
2+
* CODING CHALLENGE 1
3+
*/
4+
5+
/*
6+
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).
7+
8+
1. Store Mark's and John's mass and height in variables
9+
2. Calculate both their BMIs
10+
3. Create a boolean variable containing information about whether Mark has a higher BMI than John.
11+
4. Print a string to the console containing the variable from step 3. (Something like "Is Mark's BMI higher than John's? true").
12+
13+
GOOD LUCK 😀
14+
*/
15+
16+
let markValues = {
17+
mass: 30,
18+
height: 2.5
19+
}
20+
21+
let johnValues = {
22+
mass: 25,
23+
height: 3
24+
}
25+
26+
function whosBmiIsHigher(val1, val2){
27+
let markBmi = markValues.mass / Math.pow(markValues.height, 2);
28+
let johnBmi = johnValues.mass / Math.pow(johnValues.height, 2);
29+
30+
if(markBmi > johnBmi){
31+
console.log("At " + markBmi + "kg, Mark has a higher Bmi than John at " + johnBmi + "kg");
32+
} else {
33+
console.log("At " + johnBmi + "kg, John has a higher Bmi than John at " + markBmi + "kg");
34+
}
35+
}
36+
37+
whosBmiIsHigher(markValues, johnValues);

0 commit comments

Comments
 (0)