Skip to content

Commit 38936fa

Browse files
committed
modified: objects-and-math/studio/ObjectsStudio01.js
modified: objects-and-math/studio/ObjectsStudio02.js
1 parent 40c78a9 commit 38936fa

File tree

2 files changed

+104
-32
lines changed

2 files changed

+104
-32
lines changed
Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,98 @@
11
// Code your selectRandomEntry function here:
22

3+
function selectRandomEntry(arr) {
4+
return arr[Math.round(Math.random() * 5)];
5+
}
36

47
// Code your buildCrewArray function here:
58

6-
79
let idNumbers = [291, 414, 503, 599, 796, 890];
810

11+
let randomArr = [];
12+
let usedVal = [];
13+
14+
while (randomArr.length < 3) {
15+
let val = selectRandomEntry(idNumbers);
16+
if (!usedVal.includes(val)) {
17+
randomArr.push(val);
18+
usedVal.push(val);
19+
}
20+
}
21+
22+
console.log(randomArr);
23+
24+
console.log(selectRandomEntry(idNumbers));
25+
926
// Here are the candidates and the 'animals' array:
1027
let candidateA = {
11-
'name':'Gordon Shumway',
12-
'species':'alf',
13-
'mass':90,
14-
'o2Used':function(hrs){return 0.035*hrs},
15-
'astronautID':414
28+
name: "Gordon Shumway",
29+
species: "alf",
30+
mass: 90,
31+
o2Used: function (hrs) {
32+
return 0.035 * hrs;
33+
},
34+
astronautID: 414,
1635
};
1736
let candidateB = {
18-
'name':'Lassie',
19-
'species':'dog',
20-
'mass':19.1,
21-
'o2Used':function(hrs){return 0.030*hrs},
22-
'astronautID':503
37+
name: "Lassie",
38+
species: "dog",
39+
mass: 19.1,
40+
o2Used: function (hrs) {
41+
return 0.03 * hrs;
42+
},
43+
astronautID: 503,
2344
};
2445
let candidateC = {
25-
'name':'Jonsey',
26-
'species':'cat',
27-
'mass':3.6,
28-
'o2Used':function(hrs){return 0.022*hrs},
29-
'astronautID':796
46+
name: "Jonsey",
47+
species: "cat",
48+
mass: 3.6,
49+
o2Used: function (hrs) {
50+
return 0.022 * hrs;
51+
},
52+
astronautID: 796,
3053
};
3154
let candidateD = {
32-
'name':'Paddington',
33-
'species':'bear',
34-
'mass':31.8,
35-
'o2Used':function(hrs){return 0.047*hrs},
36-
'astronautID':291
55+
name: "Paddington",
56+
species: "bear",
57+
mass: 31.8,
58+
o2Used: function (hrs) {
59+
return 0.047 * hrs;
60+
},
61+
astronautID: 291,
3762
};
3863
let candidateE = {
39-
'name':'Pete',
40-
'species':'tortoise',
41-
'mass':417,
42-
'o2Used':function(hrs){return 0.010*hrs},
43-
'astronautID':599
64+
name: "Pete",
65+
species: "tortoise",
66+
mass: 417,
67+
o2Used: function (hrs) {
68+
return 0.01 * hrs;
69+
},
70+
astronautID: 599,
4471
};
4572
let candidateF = {
46-
'name':'Hugs',
47-
'species':'ball python',
48-
'mass':2.3,
49-
'o2Used':function(hrs){return 0.018*hrs},
50-
'astronautID':890
73+
name: "Hugs",
74+
species: "ball python",
75+
mass: 2.3,
76+
o2Used: function (hrs) {
77+
return 0.018 * hrs;
78+
},
79+
astronautID: 890,
5180
};
5281

53-
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
82+
let animals = [candidateA, candidateB, candidateC, candidateD, candidateE, candidateF];
5483

5584
// Code your template literal and console.log statements:
85+
86+
function buildCrewArray(numbers, animals) {
87+
let crew = [];
88+
while (crew.length < 3) {
89+
for (i = 0; i < animals.length; i++) {
90+
if (numbers.includes(animals[i].astronautID)) {
91+
crew.push(animals[i].name);
92+
}
93+
}
94+
}
95+
console.log(`${crew[0]}, ${crew[1]} & ${crew[2]} are going to space!`);
96+
}
97+
98+
buildCrewArray(randomArr, animals);

objects-and-math/studio/ObjectsStudio02.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
// Code your orbitCircumference function here:
22

3+
let altitude = 2000;
4+
let speed = 28000;
5+
6+
function orbitCircumference(radius) {
7+
return Math.round(2*Math.PI*radius)
8+
}
9+
10+
console.log(orbitCircumference(altitude))
311

412
// Code your missionDuration function here:
513

14+
function missionDuration(numOrbits, radius, speed) {
15+
return Math.round((numOrbits*orbitCircumference(radius))/speed*100)/100
16+
17+
}
18+
19+
console.log(`The mission will travel ${orbitCircumference(altitude)}km around the planet, and it will take ${missionDuration(5, altitude, speed)} hours to complete`)
20+
21+
missionDuration(5, altitude, speed)
622

723
// Copy/paste your selectRandomEntry function here:
824

25+
function selectRandomEntry(arr) {
26+
return arr[Math.round(Math.random() * 5)];
27+
}
928

1029
// Code your oxygenExpended function here:
1130

31+
function oxygenExpended(numOrbits, candidate, radius, speed) {
32+
let duration = missionDuration(numOrbits, radius, speed)
33+
let oxygen = Math.round(candidate.o2Used(duration)*1000)/1000;
34+
35+
console.log(`${candidate.name} will perform the spacewalk, which will last ${duration} hours and require ${oxygen} of oxygen.`)
36+
}
37+
38+
1239

1340
// Candidate data & crew array.
1441
let candidateA = {
@@ -53,6 +80,8 @@ let candidateA = {
5380
'o2Used':function(hrs){return 0.018*hrs},
5481
'astronautID':890
5582
};
83+
84+
oxygenExpended(3, candidateA, altitude, speed)
5685

5786
let crew = [candidateA,candidateC,candidateE];
5887

0 commit comments

Comments
 (0)