Skip to content

Commit f4722d9

Browse files
committed
ObjExercises
1 parent 24c7646 commit f4722d9

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

objects-and-math/exercises/ObjectExercises.js

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,84 @@ let superChimpOne = {
22
name: "Chad",
33
species: "Chimpanzee",
44
mass: 9,
5-
age: 6
5+
age: 6,
6+
astronautID: 1,
7+
move: function () {
8+
return Math.floor(Math.random()*10)
9+
}
10+
611
};
712

813
let salamander = {
914
name: "Lacey",
1015
species: "Axolotl Salamander",
1116
mass: 0.1,
12-
age: 5
17+
age: 5,
18+
astronautID: 2,
19+
move: function () {
20+
return Math.floor(Math.random()*10)
21+
}
1322
};
1423

24+
let superChimpTwo = {
25+
name: "Brad ",
26+
species: "Chimpanzee",
27+
mass: 11,
28+
age: 6,
29+
astronautID: 3,
30+
move: function () {
31+
return Math.floor(Math.random()*10)
32+
}
33+
};
34+
35+
let dog = {
36+
name: "Leroy",
37+
species: "Beagle",
38+
mass: 14,
39+
age: 5,
40+
astronautID: 4,
41+
move: function () {
42+
return Math.floor(Math.random()*10)
43+
}
44+
};
45+
46+
let lizard = {
47+
name: "Almina",
48+
species: "Tardigrade",
49+
mass: Math.round(0.0000000001*100)/10000,
50+
age: 1,
51+
astronautID: 5,
52+
move: function () {
53+
return Math.floor(Math.random()*11)
54+
}
55+
};
56+
let crew = [superChimpOne, salamander, superChimpTwo, dog, lizard];
57+
58+
crew.forEach(function(cadet){
59+
console.log(cadet.name + " is in charge of steps " + cadet.move()+ ".");
60+
});
61+
crew.forEach(function(animal){
62+
console.log(`${animal.name} is a ${animal.species}. They currently weigh ${animal.mass}kgs and are ${animal.age} years old.`)
63+
});
64+
65+
function fitnessTest(cadets){
66+
let results = [], numSteps, turns;
67+
for (let i=0; i < cadets.length; i++){
68+
numSteps = 0;
69+
turns = 0;
70+
while(numSteps < 20){
71+
numSteps += cadets[i].move();
72+
turns++;
73+
}
74+
results.push(`It took ${cadets[i].name}, ${turns} turns to take 20 steps.`)
75+
}
76+
return results;
77+
}
78+
let testResults = fitnessTest(crew);
1579

80+
testResults.forEach(result => {
81+
console.log(result);
82+
})
1683
// After you have created the other object literals, add the astronautID property to each one.
1784

1885
// Create an array to hold the animal objects.

0 commit comments

Comments
 (0)