File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed
objects-and-math/exercises Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -2,21 +2,44 @@ let superChimpOne = {
2
2
name : "Chad" ,
3
3
species : "Chimpanzee" ,
4
4
mass : 9 ,
5
- age : 6
5
+ age : 6 ,
6
+ move : function ( ) { return Math . floor ( Math . random ( ) * 11 ) }
7
+
6
8
} ;
7
9
8
10
let salamander = {
9
11
name : "Lacey" ,
10
12
species : "Axolotl Salamander" ,
11
13
mass : 0.1 ,
12
- age : 5
14
+ age : 5 ,
15
+ move : function ( ) { return Math . floor ( Math . random ( ) * 11 ) }
16
+
13
17
} ;
14
18
15
19
16
20
// After you have created the other object literals, add the astronautID property to each one.
21
+ superChimpOne [ "astronautID" ] = Math . floor ( Math . random ( ) * 10 ) + 1 ;
22
+ salamander [ "astronautID" ] = Math . floor ( Math . random ( ) * 10 ) + 1 ;
17
23
18
24
// Create an array to hold the animal objects.
19
-
25
+ let crew = [ superChimpOne , salamander ] ;
20
26
// Print out the relevant information about each animal.
27
+ console . log ( superChimpOne ) ;
28
+ console . log ( salamander ) ;
21
29
22
- // Start an animal race!
30
+ // Start an animal race!
31
+ function fitnessTest ( candidates ) {
32
+ let results = [ ] , numSteps , turns ;
33
+ for ( let i = 0 ; i < candidates . length ; i ++ ) {
34
+ numSteps = 0 ;
35
+ turns = 0 ;
36
+ while ( numSteps < 20 ) {
37
+ numSteps += candidates [ i ] . move ( ) ;
38
+ turns ++ ;
39
+ }
40
+ results . push ( `${ candidates [ i ] . name } took ${ turns } turns to take 20 steps.` ) ;
41
+ }
42
+ return results ;
43
+ }
44
+ let results = fitnessTest ( crew ) ;
45
+ console . log ( results ) ;
You can’t perform that action at this time.
0 commit comments