Skip to content

Commit 79f26ee

Browse files
committed
Complete V1
1 parent d11cbba commit 79f26ee

File tree

1 file changed

+89
-7
lines changed

1 file changed

+89
-7
lines changed

objects-and-math/exercises/ObjectExercises.js

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,105 @@ let superChimpOne = {
22
name: "Chad",
33
species: "Chimpanzee",
44
mass: 9,
5-
age: 6
5+
age: 6,
6+
astronautID: 2,
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: 3,
16+
move: function () {return Math.floor(Math.random()*11)}
1317
};
1418

19+
let fpsCooked = {
20+
name: "Brad",
21+
species: "Chimpanzee",
22+
mass: 11,
23+
age: 6,
24+
astronautID: 5,
25+
move: function () {return Math.floor(Math.random()*11)}
26+
};
27+
28+
let pupper = {
29+
name: "Leroy",
30+
species: "Beagle",
31+
mass: 14,
32+
age: 5,
33+
astronautID: 8,
34+
move: function () {return Math.floor(Math.random()*11)}
35+
};
36+
37+
let unKnown = {
38+
name: "Almina",
39+
species: "Tardigrade",
40+
mass: 0.0000000001,
41+
age: 1,
42+
astronautID: 10,
43+
move: function () {
44+
return Math.floor(Math.random()*11)
45+
}
46+
};
47+
48+
49+
let crew = [superChimpOne, salamander, fpsCooked, pupper, unKnown];
50+
51+
function crewReports(crewMember) {//. notation to call
52+
53+
console.log(`
54+
${crewMember.name} is a ${crewMember.species}.
55+
They are ${crewMember.age} years old and ${crewMember.mass} kilograms.
56+
Their ID is ${crewMember.astronautID}.`)
57+
}
58+
59+
// crew.forEach(crewReports);
60+
//for each item in the crew ARRAY run this function in ()
61+
//aka .length for arrays
62+
// --- crew.forEach(crewReports) ---
63+
// go to crew Array [superChimpOne, salamander, fpsCooked, pupper, unKnown]
64+
// run crewReports on each crewMember of crew Array
65+
console.log(".........................");
66+
let crewSteps = 0;
67+
let crewTurnCounter = 0; //must be inside loop or will not return to 0 for next member of crew
68+
let crewTurnsArray = [];
69+
70+
function fitnessTest(crewArray) { //crew will be the parameter here
71+
72+
for (let crewMate of crewArray){//loop goes through each 1 member of the array at a time
73+
crewSteps = 0;
74+
crewTurnCounter = 0; //restarts at 0 when the for loop restarts for the next member
75+
while (crewSteps < 20) {//condition for the loop
76+
77+
crewSteps += crewMate.move(); //adds the move function ammount together and updates the crewsteps of the 1 member
78+
79+
crewTurnCounter++; //counter iteration keeping track of each 1 member turn on their way to 20 steps
80+
}
81+
crewTurnsArray.push(crewMate.name + " took " + crewTurnCounter + " turns to take 20 steps.");//push the result of hte crewturncounter into the crew turns array lined up with each member
82+
}
83+
// if (crewSteps >= 20) {
84+
// console.log(`${crewMate.name} took ${crewTurnsArray} turns to take 20 steps.`);
85+
// }
86+
return crewTurnsArray;//need to return functions so that the data can be acessed outside of the function
87+
}
88+
89+
fitnessTest(crew);//use the function fitness test with the crew parameter
90+
91+
// console.log(crewTurnsArray);
92+
93+
for (let crewTurnString of crewTurnsArray) {//for loop that goes through each element in the crewturns array and prints the string element
94+
console.log(crewTurnString);
95+
console.log();
96+
}
1597

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

18-
// Add a move method to each animal object
100+
// X Add a move method to each animal object
19101

20-
// Create an array to hold the animal objects.
102+
// X Create an array to hold the animal objects.
21103

22-
// Print out the relevant information about each animal.
104+
// X Print out the relevant information about each animal.
23105

24-
// Start an animal race!
106+
// Start an animal race!

0 commit comments

Comments
 (0)