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 4c3d6df

Browse files
src: Add solution to Coding Challenge 2
1 parent 69a8da2 commit 4c3d6df

File tree

1 file changed

+75
-12
lines changed

1 file changed

+75
-12
lines changed

‎src/index.js

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,78 @@
33
// Coding Challenge 1
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);
10-
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);
15-
16-
var isMarkBMIGreaterThanJohn = markBMI > johnBMI;
17-
console.log("Is Mark's BMI greater than John's? " + isMarkBMIGreaterThanJohn);
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);
10+
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);
15+
16+
// var isMarkBMIGreaterThanJohn = markBMI > johnBMI;
17+
// console.log("Is Mark's BMI greater than John's? " + isMarkBMIGreaterThanJohn);
18+
19+
// -----------------------------------------------------------------------------
20+
// Coding Challenge 2
21+
// -----------------------------------------------------------------------------
22+
23+
var john = ( 89 + 138 + 103 ) / 3;
24+
console.log("John's ave is " + john);
25+
26+
var mike = ( 116 + 95 + 123 ) / 3;
27+
console.log("Mike's ave is " + mike);
28+
29+
var johnOrMike;
30+
if (john == mike)
31+
{
32+
johnOrMike = "DRAW";
33+
}
34+
else
35+
{
36+
johnOrMike = (john > mike) ? "John" : "Mike";
37+
}
38+
39+
var mary = ( 85 + 134 + 105 ) / 3;
40+
console.log("Mary's ave is " + mary);
41+
42+
if (johnOrMike == "DRAW")
43+
{
44+
if (mary == john)
45+
{
46+
console.log("It's a draw " + mary);
47+
}
48+
else
49+
{
50+
var winnerAve = (mary > john ? mary : john);
51+
var winner = (mary > john ? "Mary" : "John/Mike");
52+
console.log(winner + " is the winner " + winnerAve);
53+
}
54+
}
55+
else if (johnOrMike == "John")
56+
{
57+
if (mary == john)
58+
{
59+
console.log("Mary/John is the winner " + mary);
60+
}
61+
else
62+
{
63+
var winnerAve = (mary > john ? mary : john);
64+
var winner = (mary > john ? "Mary" : "John");
65+
console.log(winner + " is the winner " + winnerAve);
66+
}
67+
}
68+
else // johnOrMike == "Mike"
69+
{
70+
if (mary == mike)
71+
{
72+
console.log("Mary/Mike is the winner " + mary);
73+
}
74+
else
75+
{
76+
var winnerAve = (mary > mike ? mary : mike);
77+
var winner = (mary > mike ? "Mary" : "Mike");
78+
console.log(winner + " is the winner " + winnerAve);
79+
}
80+
}

0 commit comments

Comments
(0)

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