Skip to content

Commit 67f2c53

Browse files
Merge pull request LaunchCodeEducation#11 from LaunchCodeEducation/ch-12-objects
Chapter 12: Objects and the Math Object
2 parents 989244a + a45b3aa commit 67f2c53

File tree

6 files changed

+215
-0
lines changed

6 files changed

+215
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let tortoiseOne = {
2+
species: "Galapagos Tortoise",
3+
name: "Pete",
4+
weight: 919,
5+
age: 85,
6+
diet: ["pumpkins", "lettuce", "cabbage"]
7+
};
8+
9+
// Using a for..in loop, iterate through each property in the tortoiseOne object and print the value to the console.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function randomSelection(arr){
2+
let index = Math.floor(Math.random()*arr.length);
3+
return arr[index];
4+
}
5+
6+
let happiness = ['Hope', 'Joy', 'Peace', 'Love', 'Kindness', 'Puppies', 'Kittens', 'Tortoise'];
7+
8+
let words = ['Hello', 'World', 'Python', 'JavaScript', 'Rutabaga'];
9+
10+
for (i=0; i < 8; i++){
11+
console.log(randomSelection(happiness));
12+
}
13+
14+
//Experiment with the code above. Try to:
15+
//a) Print 3 random selections from each array.
16+
//b) Have the code randomly pick one array, and then print 2 random items from it.
17+
//c) Create a new array, then fill it with one random item from words and happiness. Print the new array.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let superChimpOne = {
2+
name: "Chad",
3+
species: "Chimpanzee",
4+
mass: 9,
5+
age: 6
6+
};
7+
8+
let salamander = {
9+
name: "Lacey",
10+
species: "Axolotl Salamander",
11+
mass: 0.1,
12+
age: 5
13+
};
14+
15+
16+
// After you have created the other object literals, add the astronautID property to each one.
17+
18+
// Create an array to hold the animal objects.
19+
20+
// Print out the relevant information about each animal.
21+
22+
// Start an animal race!
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Code your selectRandomEntry function here:
2+
3+
4+
// Code your buildCrewArray function here:
5+
6+
7+
let idNumbers = [291, 414, 503, 599, 796, 890];
8+
9+
// Here are the candidates and the 'animals' array:
10+
let candidateA = {
11+
'name':'Gordon Shumway',
12+
'species':'alf',
13+
'mass':90,
14+
'o2Used':function(hrs){return 0.035*hrs},
15+
'astronautID':414
16+
};
17+
let candidateB = {
18+
'name':'Lassie',
19+
'species':'dog',
20+
'mass':19.1,
21+
'o2Used':function(hrs){return 0.030*hrs},
22+
'astronautID':503
23+
};
24+
let candidateC = {
25+
'name':'Jonsey',
26+
'species':'cat',
27+
'mass':3.6,
28+
'o2Used':function(hrs){return 0.022*hrs},
29+
'astronautID':796
30+
};
31+
let candidateD = {
32+
'name':'Paddington',
33+
'species':'bear',
34+
'mass':31.8,
35+
'o2Used':function(hrs){return 0.047*hrs},
36+
'astronautID':291
37+
};
38+
let candidateE = {
39+
'name':'Pete',
40+
'species':'tortoise',
41+
'mass':417,
42+
'o2Used':function(hrs){return 0.010*hrs},
43+
'astronautID':599
44+
};
45+
let candidateF = {
46+
'name':'Hugs',
47+
'species':'ball python',
48+
'mass':2.3,
49+
'o2Used':function(hrs){return 0.018*hrs},
50+
'astronautID':890
51+
};
52+
53+
let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];
54+
55+
// Code your template literal and console.log statements:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Code your orbitCircumference function here:
2+
3+
4+
// Code your missionDuration function here:
5+
6+
7+
// Copy/paste your selectRandomEntry function here:
8+
9+
10+
// Code your oxygenExpended function here:
11+
12+
13+
// Candidate data & crew array.
14+
let candidateA = {
15+
'name':'Gordon Shumway',
16+
'species':'alf',
17+
'mass':90,
18+
'o2Used':function(hrs){return 0.035*hrs},
19+
'astronautID':414
20+
};
21+
let candidateB = {
22+
'name':'Lassie',
23+
'species':'dog',
24+
'mass':19.1,
25+
'o2Used':function(hrs){return 0.030*hrs},
26+
'astronautID':503
27+
};
28+
let candidateC = {
29+
'name':'Jonsey',
30+
'species':'cat',
31+
'mass':3.6,
32+
'o2Used':function(hrs){return 0.022*hrs},
33+
'astronautID':796
34+
};
35+
let candidateD = {
36+
'name':'Paddington',
37+
'species':'bear',
38+
'mass':31.8,
39+
'o2Used':function(hrs){return 0.047*hrs},
40+
'astronautID':291
41+
};
42+
let candidateE = {
43+
'name':'Pete',
44+
'species':'tortoise',
45+
'mass':417,
46+
'o2Used':function(hrs){return 0.010*hrs},
47+
'astronautID':599
48+
};
49+
let candidateF = {
50+
'name':'Hugs',
51+
'species':'ball python',
52+
'mass':2.3,
53+
'o2Used':function(hrs){return 0.018*hrs},
54+
'astronautID':890
55+
};
56+
57+
let crew = [candidateA,candidateC,candidateE];
58+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Code your crewMass function here:
2+
3+
4+
// Code your fuelRequired function here:
5+
6+
7+
// The pre-selected crew is in the array at the end of this file.
8+
// Feel free to add, remove, or switch crew members as you see fit.
9+
10+
let candidateA = {
11+
'name':'Gordon Shumway',
12+
'species':'alf',
13+
'mass':90,
14+
'o2Used':function(hrs){return 0.035*hrs},
15+
'astronautID':414
16+
};
17+
let candidateB = {
18+
'name':'Lassie',
19+
'species':'dog',
20+
'mass':19.1,
21+
'o2Used':function(hrs){return 0.030*hrs},
22+
'astronautID':503
23+
};
24+
let candidateC = {
25+
'name':'Jonsey',
26+
'species':'cat',
27+
'mass':3.6,
28+
'o2Used':function(hrs){return 0.022*hrs},
29+
'astronautID':796
30+
};
31+
let candidateD = {
32+
'name':'Paddington',
33+
'species':'bear',
34+
'mass':31.8,
35+
'o2Used':function(hrs){return 0.047*hrs},
36+
'astronautID':291
37+
};
38+
let candidateE = {
39+
'name':'Pete',
40+
'species':'tortoise',
41+
'mass':417,
42+
'o2Used':function(hrs){return 0.010*hrs},
43+
'astronautID':599
44+
};
45+
let candidateF = {
46+
'name':'Hugs',
47+
'species':'ball python',
48+
'mass':2.3,
49+
'o2Used':function(hrs){return 0.018*hrs},
50+
'astronautID':890
51+
};
52+
53+
let crew = [candidateB,candidateD,candidateF];
54+

0 commit comments

Comments
 (0)