Skip to content

Commit 9af10f2

Browse files
committed
Compeleted orbit calculations
1 parent 11dc982 commit 9af10f2

File tree

1 file changed

+87
-48
lines changed

1 file changed

+87
-48
lines changed
Lines changed: 87 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,97 @@
11
// Code your orbitCircumference function here:
2-
2+
function orbitCircumference(radius) {
3+
return Math.round(2 * Math.PI * radius);
4+
}
35

46
// Code your missionDuration function here:
5-
7+
function missionDuration(numOrbits, radius = 2000, speed = 28000) {
8+
let circumference = orbitCircumference(radius);
9+
let distance = numOrbits * circumference;
10+
let time = distance / speed;
11+
return parseFloat(time.toFixed(2));
12+
}
613

714
// Copy/paste your selectRandomEntry function here:
8-
15+
function selectRandomEntry(arrayInput) {
16+
return arrayInput[Math.floor(Math.random() * arrayInput.length)];
17+
}
918

1019
// Code your oxygenExpended function here:
11-
20+
function oxygenExpended(candidate, radius = 2000, speed = 28000) {
21+
let spacewalkTime = missionDuration(3, radius, speed);
22+
let oxygenUsed = candidate.o2Used(spacewalkTime);
23+
return `${
24+
candidate.name
25+
} will perform the spacewalk, which will last ${spacewalkTime} hours amd require ${oxygenUsed.toFixed(
26+
3
27+
)} kg of oxygen.`;
28+
}
1229

1330
// Candidate data & crew array.
1431
let candidateA = {
15-
'name':'Gordon Shumway',
16-
'species':'alf',
17-
'mass':90,
18-
'o2Used':function(hrs){return 0.035*hrs},
19-
'astronautID':414
20-
};
21-
let candidateB = {
22-
'name':'Lassie',
23-
'species':'dog',
24-
'mass':19.1,
25-
'o2Used':function(hrs){return 0.030*hrs},
26-
'astronautID':503
27-
};
28-
let candidateC = {
29-
'name':'Jonsey',
30-
'species':'cat',
31-
'mass':3.6,
32-
'o2Used':function(hrs){return 0.022*hrs},
33-
'astronautID':796
34-
};
35-
let candidateD = {
36-
'name':'Paddington',
37-
'species':'bear',
38-
'mass':31.8,
39-
'o2Used':function(hrs){return 0.047*hrs},
40-
'astronautID':291
41-
};
42-
let candidateE = {
43-
'name':'Pete',
44-
'species':'tortoise',
45-
'mass':417,
46-
'o2Used':function(hrs){return 0.010*hrs},
47-
'astronautID':599
48-
};
49-
let candidateF = {
50-
'name':'Hugs',
51-
'species':'ball python',
52-
'mass':2.3,
53-
'o2Used':function(hrs){return 0.018*hrs},
54-
'astronautID':890
55-
};
56-
57-
let crew = [candidateA,candidateC,candidateE];
58-
32+
name: "Gordon Shumway",
33+
species: "alf",
34+
mass: 90,
35+
o2Used: function (hrs) {
36+
return 0.035 * hrs;
37+
},
38+
astronautID: 414,
39+
};
40+
let candidateB = {
41+
name: "Lassie",
42+
species: "dog",
43+
mass: 19.1,
44+
o2Used: function (hrs) {
45+
return 0.03 * hrs;
46+
},
47+
astronautID: 503,
48+
};
49+
let candidateC = {
50+
name: "Jonsey",
51+
species: "cat",
52+
mass: 3.6,
53+
o2Used: function (hrs) {
54+
return 0.022 * hrs;
55+
},
56+
astronautID: 796,
57+
};
58+
let candidateD = {
59+
name: "Paddington",
60+
species: "bear",
61+
mass: 31.8,
62+
o2Used: function (hrs) {
63+
return 0.047 * hrs;
64+
},
65+
astronautID: 291,
66+
};
67+
let candidateE = {
68+
name: "Pete",
69+
species: "tortoise",
70+
mass: 417,
71+
o2Used: function (hrs) {
72+
return 0.01 * hrs;
73+
},
74+
astronautID: 599,
75+
};
76+
let candidateF = {
77+
name: "Hugs",
78+
species: "ball python",
79+
mass: 2.3,
80+
o2Used: function (hrs) {
81+
return 0.018 * hrs;
82+
},
83+
astronautID: 890,
84+
};
85+
86+
let crew = [candidateA, candidateC, candidateE];
87+
88+
let numOrbits = 5;
89+
let orbitRadius = 2000;
90+
let orbitalSpeed = 28000;
91+
let totalDistance = orbitCircumference(orbitRadius) * numOrbits;
92+
let totalDuration = missionDuration(numOrbits, orbitRadius, orbitalSpeed);
93+
console.log(
94+
`The mission will travel ${totalDistance} km around the planet, and it will take ${totalDuration} hours to complete.`
95+
);
96+
let selectedCrewMember = selectRandomEntry(crew);
97+
console.log(oxygenExpended(selectedCrewMember));

0 commit comments

Comments
 (0)