Skip to content

Commit 01609b9

Browse files
committed
Add 1st Challenge
1 parent cf3c0cb commit 01609b9

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
3+
Level: Beginner
4+
5+
CODING CHALLENGE 1
6+
7+
8+
/*
9+
10+
Mark and John are trying to compare their BMI (Body Mass Index),
11+
which is calculated using the formula: BMI = mass / height^2 = mass / (height * height).
12+
(mass in kg and height in meter).
13+
14+
1. Store Mark's and John's mass and height in variables
15+
2. Calculate both their BMIs
16+
3. Create a boolean variable containing information about whether Mark has a higher BMI than John.
17+
4. Print a string to the console containing the variable from step 3.
18+
(Something like "Is Mark's BMI higher than John's? true").
19+
20+
21+
SOLUTION 👇🏼
22+
23+
*/
24+
25+
26+
27+
28+
29+
30+
31+
32+
// With comments:
33+
34+
// Store variables for Mark
35+
36+
var markMass = 68; // kg
37+
var markHeight = 1.78; // cm
38+
39+
// Calculate the BMI
40+
var markBMI = markMass / (markHeight * markHeight);
41+
42+
// Show Marks final BMI in console
43+
console.log(Math.round(markBMI));
44+
45+
// Store variables for John
46+
47+
var johnMass = 102; // kg
48+
var johnHeight = 1.88; // cm
49+
50+
var johnBMI = johnMass / (johnHeight * johnHeight);
51+
52+
// Show John's final BMI in console
53+
console.log(Math.round(johnBMI));
54+
55+
// Who's BMI is higher?
56+
var higherBMI = markMass > johnMass;
57+
58+
// Print final result (higher BMI)
59+
var resultMessage = 'Is Mark\'s BMI higher than John\'s?' + ' ' + higherBMI;
60+
console.log(resultMessage);
61+
62+
63+
64+
/* ------------------------------------ */
65+
66+
// Without comments:
67+
68+
69+
var markMass = 68; // kg's
70+
var markHeight = 1.78; // cm's
71+
72+
var markBMI = markMass / (markHeight * markHeight);
73+
74+
console.log(Math.round(markBMI));
75+
76+
77+
var johnMass = 102;
78+
var johnHeight = 1.88;
79+
80+
var johnBMI = johnMass / (johnHeight * johnHeight);
81+
82+
console.log(Math.round(johnBMI));
83+
84+
85+
var higherBMI = markMass > johnMass;
86+
87+
var resultMessage = 'Is Mark\'s BMI higher than John\'s?' + ' ' + higherBMI;
88+
89+
console.log(resultMessage);

0 commit comments

Comments
 (0)