|
1 | 1 | let superChimpOne = {
|
2 |
| - name: "Chad", |
3 |
| - species: "Chimpanzee", |
4 |
| - mass: 9, |
5 |
| - age: 6 |
| 2 | + name: "Chad", |
| 3 | + species: "Chimpanzee", |
| 4 | + mass: 9, |
| 5 | + age: 6, |
| 6 | + move: function () { |
| 7 | + return Math.round(Math.random() * 10); |
| 8 | + }, |
6 | 9 | };
|
7 | 10 |
|
8 | 11 | let salamander = {
|
9 |
| - name: "Lacey", |
10 |
| - species: "Axolotl Salamander", |
11 |
| - mass: 0.1, |
12 |
| - age: 5 |
| 12 | + name: "Lacey", |
| 13 | + species: "Axolotl Salamander", |
| 14 | + mass: 0.1, |
| 15 | + age: 5, |
| 16 | + move: function () { |
| 17 | + return Math.round(Math.random() * 10); |
| 18 | + }, |
13 | 19 | };
|
14 | 20 |
|
| 21 | +let superChimpTwo = { |
| 22 | + name: "Brad", |
| 23 | + species: "Axolotl Salamander", |
| 24 | + mass: 11, |
| 25 | + age: 6, |
| 26 | + move: function () { |
| 27 | + return Math.round(Math.random() * 10); |
| 28 | + }, |
| 29 | +}; |
| 30 | + |
| 31 | +let beagle = { |
| 32 | + name: "Lacey", |
| 33 | + species: "Axolotl Salamander", |
| 34 | + mass: 14, |
| 35 | + age: 5, |
| 36 | + move: function () { |
| 37 | + return Math.round(Math.random() * 10); |
| 38 | + }, |
| 39 | +}; |
| 40 | + |
| 41 | +let tardigrade = { |
| 42 | + name: "Lacey", |
| 43 | + species: "Axolotl Salamander", |
| 44 | + mass: 0.00000000001, |
| 45 | + age: 1, |
| 46 | + move: function () { |
| 47 | + return Math.round(Math.random() * 10); |
| 48 | + }, |
| 49 | +}; |
15 | 50 |
|
16 | 51 | // After you have created the other object literals, add the astronautID property to each one.
|
17 | 52 |
|
| 53 | +superChimpOne["astronautID"] = 1; |
| 54 | +salamander["astronautID"] = 2; |
| 55 | +superChimpTwo["astronautID"] = 3; |
| 56 | +beagle["astronautID"] = 4; |
| 57 | +tardigrade["astronautID"] = 5; |
| 58 | + |
18 | 59 | // Add a move method to each animal object
|
19 | 60 |
|
20 | 61 | // Create an array to hold the animal objects.
|
21 | 62 |
|
| 63 | +let animalArr = [superChimpOne, salamander, superChimpTwo, beagle, tardigrade]; |
| 64 | + |
22 | 65 | // Print out the relevant information about each animal.
|
23 | 66 |
|
| 67 | +animalArr.forEach((animal) => { |
| 68 | + console.log(`${animal.name} is a ${animal.species} with a mass of ${animal.mass}kg. ${animal.name} is ${animal.age} years old and moves at a pace of ${animal.move()}`); |
| 69 | +}); |
| 70 | + |
24 | 71 | // Start an animal race!
|
| 72 | + |
| 73 | +function fitnessTest(arr) { |
| 74 | + arr.forEach((animal) => { |
| 75 | + let steps = animal.move(); |
| 76 | + let turns = 0; |
| 77 | + let totalSteps = 0; |
| 78 | + |
| 79 | + while (totalSteps < 20) { |
| 80 | + totalSteps += steps; |
| 81 | + turns++; |
| 82 | + } |
| 83 | + |
| 84 | + console.log( |
| 85 | + `${animal.name} the ${animal.species} completed the race in ${turns} turns, moving a total of ${totalSteps} steps at a pace of ${steps} steps per turn.` |
| 86 | + ); |
| 87 | + }); |
| 88 | +} |
| 89 | + |
| 90 | +fitnessTest(animalArr); |
0 commit comments