Skip to content

Commit 37075b0

Browse files
committed
studio 1
1 parent c2ed0d0 commit 37075b0

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

objects-and-math/studio/ObjectsStudio01.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
// Code your selectRandomEntry function here:
2+
function selectRandomEntry(arr){
3+
let index = Math.floor(Math.random()*arr.length);
4+
return arr[index];
5+
}
26

7+
let idNumbers = [291, 414, 503, 599, 796, 890];
8+
let crewArray = [];
39

10+
//we have an array. we want to call the method randomly 3 times,
11+
// store it as a temp,
12+
// check and see if the array already has the number,
13+
// if it doenst match, add to the crew array, if it does, repeat
14+
//call three times
15+
416
// Code your buildCrewArray function here:
517

18+
while (crewArray.length <3) {
619

7-
let idNumbers = [291, 414, 503, 599, 796, 890];
20+
let temp = (selectRandomEntry(idNumbers));
21+
if(!crewArray.includes(temp)){
22+
crewArray.push(temp);
23+
}
24+
}
25+
26+
console.log(crewArray);
27+
828

929
// Here are the candidates and the 'animals' array:
1030
let candidateA = {
@@ -51,5 +71,17 @@ let candidateF = {
5171
};
5272

5373
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
74+
let crewArrayFinal = [];
75+
76+
function lucky(idNumbers, objects){
77+
for(let i = 0; i < animals.length; i++){
78+
if(idNumbers.includes(objects[i].astronautID)){
79+
crewArrayFinal.push(objects[i].name);
80+
}
81+
}
82+
83+
}lucky(crewArray, animals);
5484

5585
// Code your template literal and console.log statements:
86+
//'____, ____, and ____ are going to space!'
87+
console.log(`${crewArrayFinal[0]}, ${crewArrayFinal[1]}, and ${crewArrayFinal[2]} are going to space!`);

0 commit comments

Comments
 (0)