1
1
// Code your selectRandomEntry function here:
2
+ function selectRandomEntry ( arr ) {
3
+ let index = Math . floor ( Math . random ( ) * arr . length ) ;
4
+ return arr [ index ] ;
5
+ }
2
6
7
+ let idNumbers = [ 291 , 414 , 503 , 599 , 796 , 890 ] ;
8
+ let crewArray = [ ] ;
3
9
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
+
4
16
// Code your buildCrewArray function here:
5
17
18
+ while ( crewArray . length < 3 ) {
6
19
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
+
8
28
9
29
// Here are the candidates and the 'animals' array:
10
30
let candidateA = {
@@ -51,5 +71,17 @@ let candidateF = {
51
71
} ;
52
72
53
73
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 ) ;
54
84
55
85
// 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