Skip to content

Commit 40c78a9

Browse files
committed
modified: objects-and-math/exercises/ObjectExercises.js
1 parent 1c938f1 commit 40c78a9

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed
Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,90 @@
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+
move: function () {
7+
return Math.round(Math.random() * 10);
8+
},
69
};
710

811
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+
},
1319
};
1420

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+
};
1550

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

53+
superChimpOne["astronautID"] = 1;
54+
salamander["astronautID"] = 2;
55+
superChimpTwo["astronautID"] = 3;
56+
beagle["astronautID"] = 4;
57+
tardigrade["astronautID"] = 5;
58+
1859
// Add a move method to each animal object
1960

2061
// Create an array to hold the animal objects.
2162

63+
let animalArr = [superChimpOne, salamander, superChimpTwo, beagle, tardigrade];
64+
2265
// Print out the relevant information about each animal.
2366

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+
2471
// 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

Comments
 (0)