Skip to content

Commit b7dd569

Browse files
committed
completed object/math studio
1 parent b5b0d7c commit b7dd569

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

objects-and-math/studio/ObjectsStudio01.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
// Code your selectRandomEntry function here:
22

3+
function selectRandomEntry(array){
4+
let randomIndex = Math.floor(Math.random() * array.length);
5+
return array[randomIndex];
6+
}
37

4-
// Code your buildCrewArray function here:
8+
function getThreeIds(array) {
9+
let newArray = [];
10+
while (newArray.length < 3) {
11+
let selectedItem = selectRandomEntry(array);
12+
if (newArray.includes(selectedItem) === false) {
13+
newArray.push(selectedItem);
14+
}
15+
}
16+
return newArray;
17+
}
518

19+
// Code your buildCrewArray function here:
20+
function buildCrewArray(array1, array2){
21+
let crew = [];
22+
for (let candidate in array2) {
23+
if (array1.includes(array2[candidate].astronautID) === true) {
24+
crew.push(array2[candidate].name);
25+
}
26+
}
27+
return crew;
28+
}
629

730
let idNumbers = [291, 414, 503, 599, 796, 890];
831

@@ -53,3 +76,6 @@ let candidateF = {
5376
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
5477

5578
// Code your template literal and console.log statements:
79+
80+
let selectedCrew = buildCrewArray(getThreeIds(idNumbers), animals);
81+
console.log(`${selectedCrew[0]}, ${selectedCrew[1]}, and ${selectedCrew[2]} are going to space!`)

objects-and-math/studio/ObjectsStudio02.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
// Code your orbitCircumference function here:
22

3+
let altitude = 2000;
4+
let orbitalSpeed = 28000;
5+
let orbitsComplete = 5;
36

4-
// Code your missionDuration function here:
7+
function orbitCircumference(orbit) {
8+
return Math.round(2 * Math.PI * (orbit + 6378));
9+
}
510

11+
// Code your missionDuration function here:
12+
function missionDuration(orbitsComplete, orbitCircumfrence, orbitSpeed) {
13+
return Math.round(((orbitsComplete * orbitCircumfrence) / orbitSpeed) * 1000) / 1000;
14+
}
615

716
// Copy/paste your selectRandomEntry function here:
8-
17+
function selectRandomEntry(array){
18+
let randomIndex = Math.floor(Math.random() * array.length);
19+
return array[randomIndex];
20+
}
921

1022
// Code your oxygenExpended function here:
23+
function oxygenExpended () {
24+
let hours = missionDuration(3, orbitCircumference(altitude), orbitalSpeed);
25+
let crewMember = selectRandomEntry(crew);
26+
let oxygenWeight = Math.round(crewMember.o2Used(hours) * 10000) / 10000;
27+
28+
return [crewMember.name, hours, oxygenWeight];
29+
}
1130

1231

1332
// Candidate data & crew array.
@@ -54,5 +73,12 @@ let candidateA = {
5473
'astronautID':890
5574
};
5675

57-
let crew = [candidateA,candidateC,candidateE];
58-
76+
let crew = [candidateA,candidateC,candidateE];
77+
78+
let circumfrence = orbitCircumference(altitude);
79+
let duration = missionDuration(orbitsComplete, circumfrence, orbitalSpeed);
80+
console.log(`The mission will travel ${orbitsComplete * circumfrence} km around the planet, and it will take ${duration} hours to complete.`);
81+
82+
let finalResult = oxygenExpended();
83+
84+
console.log(`${finalResult[0]} will perform the spacewalk, which will last ${finalResult[1]} hours and require ${finalResult[2]} kg of oxygen.`)

0 commit comments

Comments
 (0)