Skip to content

Commit 457a11d

Browse files
committed
objects excecise done
1 parent 0e7bd5c commit 457a11d

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

objects-and-math/exercises/ObjectExercises.js

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,77 @@ let superChimpOne = {
22
name: "Chad",
33
species: "Chimpanzee",
44
mass: 9,
5-
age: 6
5+
age: 6,
6+
astronautID: 1,
7+
move: function() {return Math.floor(Math.random() * 11)}
68
};
79

810
let salamander = {
911
name: "Lacey",
1012
species: "Axolotl Salamander",
1113
mass: 0.1,
12-
age: 5
14+
age: 5,
15+
astronautID: 2,
16+
move: function() {return Math.floor(Math.random() * 11)}
1317
};
1418

19+
let superChimpTwo = {
20+
name: "Brad",
21+
species: "Chimpanzee",
22+
mass: 11,
23+
age: 6,
24+
astronautID: 3,
25+
move: function() {return Math.floor(Math.random() * 11)}
26+
};
27+
28+
let spaceDog = {
29+
name: "Leroy",
30+
species: "Beagle",
31+
mass: 14,
32+
age: 5,
33+
astronautID: 4,
34+
move: function() {return Math.floor(Math.random() * 11)}
35+
}
36+
37+
let invincibleBug = {
38+
name: "Almina",
39+
species: "Tardigrade",
40+
mass: 0.0000000001,
41+
age: 1,
42+
astronautID: 5,
43+
move: function() {return Math.floor(Math.random() * 11)}
44+
}
45+
1546

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

1849
// Create an array to hold the animal objects.
1950

51+
let crew = [superChimpOne, salamander, superChimpTwo, spaceDog, invincibleBug];
52+
2053
// Print out the relevant information about each animal.
2154

22-
// Start an animal race!
55+
function crewReports(obj) {
56+
console.log(`${obj.name} is a ${obj.species}. They are ${obj.age} years old and ${obj.mass} kilograms. Their ID is ${obj.astronautID}.`)
57+
}
58+
59+
// Start an animal race!
60+
61+
function fitnessTest(arr) {
62+
results = []
63+
for (let i = 0; i < arr.length; i++) {
64+
let done = false;
65+
let total = 0;
66+
let turns = 0;
67+
while (total < 20){
68+
total += arr[i].move();
69+
turns ++;
70+
}
71+
results.push(`${arr[i].name} took ${turns} turns to take 20 steps.`)
72+
}
73+
return results;
74+
}
75+
76+
for (let i = 0; i < crew.length; i++) {
77+
console.log(fitnessTest(crew)[i])
78+
}

0 commit comments

Comments
 (0)