Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d5f507d

Browse files
chore: Put the solutions to the coding challenges in separate files
1 parent 4c3d6df commit d5f507d

File tree

4 files changed

+65
-14
lines changed

4 files changed

+65
-14
lines changed
File renamed without changes.

‎src/challenges/1/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
// -----------------------------------------------------------------------------
3+
// Coding Challenge 1
4+
// -----------------------------------------------------------------------------
5+
6+
/*
7+
Mark and John are trying to compare their BMI (Body Mass Index),
8+
which is calculated using the formula:
9+
BMI = mass / height^2
10+
= mass / (height * height)
11+
(mass in kg and height in meter).
12+
13+
1. Store Mark's and John's mass and height in variables
14+
2. Calculate both their BMIs
15+
3. Create a boolean variable containing information about whether
16+
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+
GOOD LUCK 😀
21+
*/
22+
23+
var markMass = Number(prompt("What is Mark's mass?"));
24+
var markHeight = Number(prompt("What is Mark's height?"));
25+
var markBMI = markMass / (markHeight ** 2);
26+
console.log("Mark's BMI: " + markBMI);
27+
28+
var johnMass = Number(prompt("What is John's mass?"));
29+
var johnHeight = Number(prompt("What is John's height?"));
30+
var johnBMI = johnMass / (johnHeight ** 2);
31+
console.log("John's BMI: " + johnBMI);
32+
33+
var isMarkBMIGreaterThanJohn = markBMI > johnBMI;
34+
console.log("Is Mark's BMI greater than John's? " + isMarkBMIGreaterThanJohn);

‎src/challenges/2/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JavaScript Tutorials</title>
6+
</head>
7+
8+
<body>
9+
<h1>TEST PAGE</h1>
10+
</body>
11+
12+
<script src="index.js"></script>
13+
</html>

‎src/index.js renamed to ‎src/challenges/2/index.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11

22
// -----------------------------------------------------------------------------
3-
// Coding Challenge 1
3+
// Coding Challenge 2
44
// -----------------------------------------------------------------------------
55

6-
// var markMass = Number(prompt("What is Mark's mass?"));
7-
// var markHeight = Number(prompt("What is Mark's height?"));
8-
// var markBMI = markMass / (markHeight ** 2);
9-
// console.log("Mark's BMI: " + markBMI);
6+
/*
7+
John and Mike both play basketball in different teams. In the latest 3 games,
8+
John's team scored 89, 120 and 103 points, while Mike's team scored 116, 94
9+
and 123 points.
1010
11-
// var johnMass = Number(prompt("What is John's mass?"));
12-
// var johnHeight = Number(prompt("What is John's height?"));
13-
// var johnBMI = johnMass / (johnHeight ** 2);
14-
// console.log("John's BMI: " + johnBMI);
11+
1. Calculate the average score for each team
12+
2. Decide which teams wins in average (highest average score), and print the
13+
winner to the console. Also include the average score in the output.
14+
3. Then change the scores to show different winners. Don't forget to take into
15+
account there might be a draw (the same average score)
1516
16-
// var isMarkBMIGreaterThanJohn = markBMI > johnBMI;
17-
// console.log("Is Mark's BMI greater than John's? " + isMarkBMIGreaterThanJohn);
17+
4. EXTRA: Mary also plays basketball, and her team scored 97, 134 and 105 points.
18+
Like before, log the average winner to the console. HINT: you will need the
19+
&& operator to take the decision. If you can't solve this one, just watch the
20+
solution, it's no problem :)
21+
5. Like before, change the scores to generate different winners, keeping in mind
22+
there might be draws.
1823
19-
// -----------------------------------------------------------------------------
20-
// Coding Challenge 2
21-
// -----------------------------------------------------------------------------
24+
GOOD LUCK 😀
25+
*/
2226

2327
var john = ( 89 + 138 + 103 ) / 3;
2428
console.log("John's ave is " + john);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /