Skip to content

Commit 9a76811

Browse files
committed
Completed the Objects and Math exercise
1 parent 094f264 commit 9a76811

File tree

1 file changed

+65
-10
lines changed

1 file changed

+65
-10
lines changed
Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
11
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+
astronautID: 1,
7+
move: function () {
8+
return Math.floor(Math.random() * 11);
9+
},
610
};
711

812
let salamander = {
9-
name: "Lacey",
10-
species: "Axolotl Salamander",
11-
mass: 0.1,
12-
age: 5
13+
name: "Lacey",
14+
species: "Axolotl Salamander",
15+
mass: 0.1,
16+
age: 5,
17+
astronautID: 2,
18+
move: function () {
19+
return Math.floor(Math.random() * 11);
20+
},
21+
};
22+
let superChimpTwo = {
23+
name: "Brad",
24+
species: "Chimpanzee",
25+
mass: 11,
26+
age: 6,
27+
astronautID: 3,
28+
move: function () {
29+
return Math.floor(Math.random() * 11);
30+
},
31+
};
32+
let dog = {
33+
name: "Leroy",
34+
species: "Beagle",
35+
mass: 14,
36+
age: 5,
37+
astronautID: 4,
38+
move: function () {
39+
return Math.floor(Math.random() * 11);
40+
},
41+
};
42+
let waterBear = {
43+
name: "Almina",
44+
species: "Tardigrade",
45+
mass: 0.0000000001,
46+
age: 1,
47+
astronautID: 5,
48+
move: function () {
49+
return Math.floor(Math.random() * 11);
50+
},
1351
};
14-
1552

1653
// After you have created the other object literals, add the astronautID property to each one.
1754

1855
// Add a move method to each animal object
1956

2057
// Create an array to hold the animal objects.
58+
let crew = [superChimpOne, superChimpTwo, salamander, dog, waterBear];
2159

2260
// Print out the relevant information about each animal.
23-
61+
function crewReports(animal) {
62+
return `${animal.name} is a ${animal.species}. They are ${animal.age} years old and ${animal.mass} kilograms. Their ID is ${animal.astronautID}.`;
63+
}
64+
crew.forEach((animal) => console.log(crewReports(animal)));
2465
// Start an animal race!
66+
function fitnessTest(crew) {
67+
let results = crew.map((animal) => {
68+
let steps = 0;
69+
let turns = 0;
70+
while (steps < 20) {
71+
steps += animal.move();
72+
turns++;
73+
}
74+
return `${animal.name} took ${turns} turns to take 20 steps.`;
75+
});
76+
return results;
77+
}
78+
let raceResults = fitnessTest(crew);
79+
raceResults.forEach((result) => console.log(result));

0 commit comments

Comments
 (0)