Skip to content

Commit 1879429

Browse files
committed
finished studio
1 parent 53145df commit 1879429

2 files changed

Lines changed: 186 additions & 85 deletions

File tree

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,97 @@
11
// Code your selectRandomEntry function here:
2-
2+
function selectRandomEntry(array) {
3+
const randomIndex = Math.floor(Math.random() * array.length);
4+
return array[randomIndex];
5+
}
36

47
// Code your buildCrewArray function here:
5-
6-
7-
let idNumbers = [291, 414, 503, 599, 796, 890];
8-
98
// Here are the candidates and the 'animals' array:
109
let candidateA = {
11-
'name':'Gordon Shumway',
12-
'species':'alf',
13-
'mass':90,
14-
'o2Used':function(hrs){return 0.035*hrs},
15-
'astronautID':414
10+
name: "Gordon Shumway",
11+
species: "alf",
12+
mass: 90,
13+
o2Used: function (hrs) {
14+
return 0.035 * hrs;
15+
},
16+
astronautID: 414,
1617
};
1718
let candidateB = {
18-
'name':'Lassie',
19-
'species':'dog',
20-
'mass':19.1,
21-
'o2Used':function(hrs){return 0.030*hrs},
22-
'astronautID':503
19+
name: "Lassie",
20+
species: "dog",
21+
mass: 19.1,
22+
o2Used: function (hrs) {
23+
return 0.03 * hrs;
24+
},
25+
astronautID: 503,
2326
};
2427
let candidateC = {
25-
'name':'Jonsey',
26-
'species':'cat',
27-
'mass':3.6,
28-
'o2Used':function(hrs){return 0.022*hrs},
29-
'astronautID':796
28+
name: "Jonsey",
29+
species: "cat",
30+
mass: 3.6,
31+
o2Used: function (hrs) {
32+
return 0.022 * hrs;
33+
},
34+
astronautID: 796,
3035
};
3136
let candidateD = {
32-
'name':'Paddington',
33-
'species':'bear',
34-
'mass':31.8,
35-
'o2Used':function(hrs){return 0.047*hrs},
36-
'astronautID':291
37+
name: "Paddington",
38+
species: "bear",
39+
mass: 31.8,
40+
o2Used: function (hrs) {
41+
return 0.047 * hrs;
42+
},
43+
astronautID: 291,
3744
};
3845
let candidateE = {
39-
'name':'Pete',
40-
'species':'tortoise',
41-
'mass':417,
42-
'o2Used':function(hrs){return 0.010*hrs},
43-
'astronautID':599
46+
name: "Pete",
47+
species: "tortoise",
48+
mass: 417,
49+
o2Used: function (hrs) {
50+
return 0.01 * hrs;
51+
},
52+
astronautID: 599,
4453
};
4554
let candidateF = {
46-
'name':'Hugs',
47-
'species':'ball python',
48-
'mass':2.3,
49-
'o2Used':function(hrs){return 0.018*hrs},
50-
'astronautID':890
55+
name: "Hugs",
56+
species: "ball python",
57+
mass: 2.3,
58+
o2Used: function (hrs) {
59+
return 0.018 * hrs;
60+
},
61+
astronautID: 890,
5162
};
5263

53-
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
64+
let animals = [
65+
candidateA,
66+
candidateB,
67+
candidateC,
68+
candidateD,
69+
candidateE,
70+
candidateF,
71+
];
72+
let idNumbers = [291, 414, 503, 599, 796, 890];
73+
let crew = [];
74+
75+
function luckyCandidateSelection(idNumbers, candidates) {
76+
let selectedCandidates = [];
77+
78+
while (selectedCandidates.length < 3) {
79+
let candidate = selectRandomEntry(candidates);
80+
if (
81+
idNumbers.includes(candidate.astronautID) &&
82+
!selectedCandidates.includes(candidate)
83+
) {
84+
selectedCandidates.push(candidate);
85+
}
86+
}
87+
88+
let names = selectedCandidates.map((animal) => animal.name);
89+
let message = `${names.slice(0, -1).join(", ")}, and ${names.slice(
90+
-1
91+
)} are going to space!`;
92+
console.log(message);
93+
return selectedCandidates;
94+
}
5495

96+
let selectedCrew = luckyCandidateSelection(idNumbers, animals);
5597
// Code your template literal and console.log statements:
Lines changed: 108 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,117 @@
1-
// Code your orbitCircumference function here:
1+
// Candidate data & crew array.
2+
let candidateA = {
3+
name: "Gordon Shumway",
4+
species: "alf",
5+
mass: 90,
6+
o2Used: function (hrs) {
7+
return 0.035 * hrs;
8+
},
9+
astronautID: 414,
10+
};
11+
let candidateB = {
12+
name: "Lassie",
13+
species: "dog",
14+
mass: 19.1,
15+
o2Used: function (hrs) {
16+
return 0.03 * hrs;
17+
},
18+
astronautID: 503,
19+
};
20+
let candidateC = {
21+
name: "Jonsey",
22+
species: "cat",
23+
mass: 3.6,
24+
o2Used: function (hrs) {
25+
return 0.022 * hrs;
26+
},
27+
astronautID: 796,
28+
};
29+
let candidateD = {
30+
name: "Paddington",
31+
species: "bear",
32+
mass: 31.8,
33+
o2Used: function (hrs) {
34+
return 0.047 * hrs;
35+
},
36+
astronautID: 291,
37+
};
38+
let candidateE = {
39+
name: "Pete",
40+
species: "tortoise",
41+
mass: 417,
42+
o2Used: function (hrs) {
43+
return 0.01 * hrs;
44+
},
45+
astronautID: 599,
46+
};
47+
let candidateF = {
48+
name: "Hugs",
49+
species: "ball python",
50+
mass: 2.3,
51+
o2Used: function (hrs) {
52+
return 0.018 * hrs;
53+
},
54+
astronautID: 890,
55+
};
256

57+
let crew = [candidateA, candidateC, candidateE];
58+
const numOrbits = 5;
59+
60+
// Code your orbitCircumference function here:
61+
const calculateOrbitCircumference = (radius) => {
62+
const circumference = 2 * Math.PI * radius;
63+
return Math.round(circumference);
64+
};
365

466
// Code your missionDuration function here:
67+
const missionDuration = (
68+
numOrbits,
69+
orbitRadius = 2000,
70+
orbitalSpeed = 28000
71+
) => {
72+
const orbitCircumference = calculateOrbitCircumference(orbitRadius);
73+
const distance = numOrbits * orbitCircumference;
74+
const timeInHours = distance / orbitalSpeed;
75+
const roundedTime = timeInHours.toFixed(2);
76+
return parseFloat(roundedTime);
77+
};
578

79+
function selectRandomEntry(array) {
80+
const randomIndex = Math.floor(Math.random() * array.length);
81+
return array[randomIndex];
82+
}
683

7-
// Copy/paste your selectRandomEntry function here:
84+
const oxygenExpended = (candidate, numOrbits, orbitRadius, orbitalSpeed) => {
85+
const spacewalkTime = missionDuration(numOrbits, orbitRadius, orbitalSpeed);
86+
const oxygenUsed = candidate.o2Used(spacewalkTime);
87+
return `${
88+
candidate.name
89+
} will perform the spacewalk, which will last ${spacewalkTime.toFixed(
90+
2
91+
)} hours and require ${oxygenUsed.toFixed(3)} kg of oxygen.`;
92+
};
893

94+
let orbitRadius = 2000;
95+
let orbitalSpeed = 28000;
96+
const selectedCandidate = selectRandomEntry(crew);
97+
const spacewalkInfo = oxygenExpended(
98+
selectedCandidate,
99+
numOrbits,
100+
orbitRadius,
101+
orbitalSpeed
102+
);
9103

10-
// Code your oxygenExpended function here:
104+
console.log(
105+
`The circumference of the orbit is approximately ${calculateOrbitCircumference(
106+
orbitRadius
107+
)} kilometers.`
108+
);
11109

110+
const duration = missionDuration(numOrbits, orbitRadius, orbitalSpeed);
111+
console.log(
112+
`The mission will travel ${
113+
calculateOrbitCircumference(orbitRadius) * numOrbits
114+
} km around the planet, and it will take ${duration} hours to complete.`
115+
);
12116

13-
// Candidate data & crew array.
14-
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-
117+
console.log(spacewalkInfo);

0 commit comments

Comments
 (0)