forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectStudio01
More file actions
82 lines (71 loc) · 1.89 KB
/
Copy pathObjectStudio01
File metadata and controls
82 lines (71 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Code your selectRandomEntry function here:
let idNumbers = [291, 414, 503, 599, 796, 890];
function selectRandomEntry(array){
return Math.floor(Math.random() * array.length);
}
// console.log(selectRandomEntry(idNumbers));
// Code your buildCrewArray function here:
let crewArray = []
while (crewArray.length < 3){
const selectedID = idNumbers[selectRandomEntry(idNumbers)];
if (!crewArray.includes(selectedID)){
crewArray.push(selectedID);
}
}
console.log(crewArray);
// Here are the candidates and the 'animals' array:
let candidateA = {
'name':'Gordon Shumway',
'species':'alf',
'mass':90,
'o2Used':function(hrs){return 0.035*hrs},
'astronautID':414
};
let candidateB = {
'name':'Lassie',
'species':'dog',
'mass':19.1,
'o2Used':function(hrs){return 0.030*hrs},
'astronautID':503
};
let candidateC = {
'name':'Jonsey',
'species':'cat',
'mass':3.6,
'o2Used':function(hrs){return 0.022*hrs},
'astronautID':796
};
let candidateD = {
'name':'Paddington',
'species':'bear',
'mass':31.8,
'o2Used':function(hrs){return 0.047*hrs},
'astronautID':291
};
let candidateE = {
'name':'Pete',
'species':'tortoise',
'mass':417,
'o2Used':function(hrs){return 0.010*hrs},
'astronautID':599
};
let candidateF = {
'name':'Hugs',
'species':'ball python',
'mass':2.3,
'o2Used':function(hrs){return 0.018*hrs},
'astronautID':890
};
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
let selectedCrew = [];
// Code your template literal and console.log statements:
//crewArray & animals
function announcment(animals,crewArray){
for (let i = 0; i < animals.length; i++)
if (crewArray.includes(animals[i].astronautID)){
selectedCrew.push(animals[i]);
}
return selectedCrew
};
console.log(announcment(animals,crewArray));
console.log(`${selectedCrew[0].name}, ${selectedCrew[1].name}, and ${selectedCrew[2].name} are going to space!`);