Skip to content

Commit cc0eb56

Browse files
committed
object exercises completed
1 parent 33ad939 commit cc0eb56

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

objects-and-math/exercises/ObjectExercises.js

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,83 @@ 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()*10)}
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()*10)}
1317
};
1418

19+
let chimpanzee = {
20+
name: "Brad",
21+
species: "Chimpanzee",
22+
mass: 11,
23+
age: 6,
24+
astronautID: 3,
25+
move: function() {return Math.floor(Math.random()*10)}
26+
};
27+
28+
let beagle = {
29+
name: "Leroy",
30+
species: "Beagle",
31+
mass: 14,
32+
age: 5,
33+
astronautID: 4,
34+
move: function() {return Math.floor(Math.random()*10)}
35+
};
36+
37+
let tardigrade = {
38+
name: "Almina",
39+
species: "Tardigrade",
40+
mass: 0.0000000001,
41+
age: 1,
42+
astronautID: 5,
43+
move: function(){return Math.floor(Math.random()*10)}
44+
};
45+
46+
47+
let crew = [tardigrade, beagle, chimpanzee, salamander, superChimpOne];
48+
49+
function crewReports(animal){
50+
console.log(animal.name , "is a" , animal.species + ". They are" , animal.age , "years old and" , animal.mass , "kilograms. Their ID is" , animal.astronautID + ".")
51+
}
52+
53+
crewReports(superChimpOne)
54+
crewReports(tardigrade)
55+
56+
for (let i = 0; i < crew.length; i++){
57+
crewReports(crew[i])
58+
}
59+
60+
function fitnessTest(arr){
61+
let results = [];
62+
63+
for (let i = 0; i < arr.length; i++){
64+
let stepsTaken = 0;
65+
let turnsTaken = 0;
66+
while(stepsTaken < 20){
67+
stepsTaken += arr[i].move();
68+
turnsTaken++
69+
}
70+
results.push(`${arr[i].name} took ${turnsTaken} turns to take 20 steps.`);
71+
}
72+
return results
73+
}
74+
console.log(fitnessTest(crew))
75+
1576

16-
// After you have created the other object literals, add the astronautID property to each one.
77+
// After you have created the other object literals, add the astronautID property to each one.
1778

18-
// Add a move method to each animal object
79+
// Add a move method to each animal object
1980

20-
// Create an array to hold the animal objects.
81+
// Create an array to hold the animal objects.
2182

2283
// Print out the relevant information about each animal.
2384

0 commit comments

Comments
 (0)