Skip to content

Commit 6106be9

Browse files
committed
objectexercise
1 parent 09320fe commit 6106be9

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

objects-and-math/exercises/ObjectExercises.js

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

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

1519

1620
// After you have created the other object literals, add the astronautID property to each one.
21+
superChimpOne["astronautID"] =Math.floor(Math.random()*10)+1;
22+
salamander["astronautID"]=Math.floor(Math.random()*10)+1;
1723

1824
// Create an array to hold the animal objects.
19-
25+
let crew = [superChimpOne,salamander];
2026
// Print out the relevant information about each animal.
27+
console.log(superChimpOne);
28+
console.log(salamander);
2129

22-
// Start an animal race!
30+
// Start an animal race!
31+
function fitnessTest(candidates){
32+
let results = [], numSteps, turns;
33+
for (let i = 0; i < candidates.length; i++){
34+
numSteps = 0;
35+
turns = 0;
36+
while(numSteps < 20){
37+
numSteps += candidates[i].move();
38+
turns++;
39+
}
40+
results.push(`${candidates[i].name} took ${turns} turns to take 20 steps.`);
41+
}
42+
return results;
43+
}
44+
let results=fitnessTest(crew);
45+
console.log(results);

0 commit comments

Comments
 (0)