Skip to content

Commit

Permalink
Merge pull request LaunchCodeEducation#11 from LaunchCodeEducation/ch…
Browse files Browse the repository at this point in the history
…-12-objects

Chapter 12: Objects and the Math Object
  • Loading branch information
gildedgardenia authored Sep 19, 2023
2 parents 989244a + a45b3aa commit 67f2c53
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 0 deletions.
9 changes: 9 additions & 0 deletions objects-and-math/chapter-examples/ForInLoop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let tortoiseOne = {
species: "Galapagos Tortoise",
name: "Pete",
weight: 919,
age: 85,
diet: ["pumpkins", "lettuce", "cabbage"]
};

// Using a for..in loop, iterate through each property in the tortoiseOne object and print the value to the console.
17 changes: 17 additions & 0 deletions objects-and-math/chapter-examples/KindnessSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function randomSelection(arr){
let index = Math.floor(Math.random()*arr.length);
return arr[index];
}

let happiness = ['Hope', 'Joy', 'Peace', 'Love', 'Kindness', 'Puppies', 'Kittens', 'Tortoise'];

let words = ['Hello', 'World', 'Python', 'JavaScript', 'Rutabaga'];

for (i=0; i < 8; i++){
console.log(randomSelection(happiness));
}

//Experiment with the code above. Try to:
//a) Print 3 random selections from each array.
//b) Have the code randomly pick one array, and then print 2 random items from it.
//c) Create a new array, then fill it with one random item from words and happiness. Print the new array.
22 changes: 22 additions & 0 deletions objects-and-math/exercises/ObjectExercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let superChimpOne = {
name: "Chad",
species: "Chimpanzee",
mass: 9,
age: 6
};

let salamander = {
name: "Lacey",
species: "Axolotl Salamander",
mass: 0.1,
age: 5
};


// After you have created the other object literals, add the astronautID property to each one.

// Create an array to hold the animal objects.

// Print out the relevant information about each animal.

// Start an animal race!
55 changes: 55 additions & 0 deletions objects-and-math/studio/ObjectsStudio01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Code your selectRandomEntry function here:


// Code your buildCrewArray function here:


let idNumbers = [291, 414, 503, 599, 796, 890];

// Here are the candidates and the 'animals' array:
let candidateA = {
'name':'Gordon Shumway',
'species':'alf',
'mass':90,
'o2Used':function(hrs){return 0.035*hrs},
'astronautID':414
};
let candidateB = {
'name':'Lassie',
'species':'dog',
'mass':19.1,
'o2Used':function(hrs){return 0.030*hrs},
'astronautID':503
};
let candidateC = {
'name':'Jonsey',
'species':'cat',
'mass':3.6,
'o2Used':function(hrs){return 0.022*hrs},
'astronautID':796
};
let candidateD = {
'name':'Paddington',
'species':'bear',
'mass':31.8,
'o2Used':function(hrs){return 0.047*hrs},
'astronautID':291
};
let candidateE = {
'name':'Pete',
'species':'tortoise',
'mass':417,
'o2Used':function(hrs){return 0.010*hrs},
'astronautID':599
};
let candidateF = {
'name':'Hugs',
'species':'ball python',
'mass':2.3,
'o2Used':function(hrs){return 0.018*hrs},
'astronautID':890
};

let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF];

// Code your template literal and console.log statements:
58 changes: 58 additions & 0 deletions objects-and-math/studio/ObjectsStudio02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Code your orbitCircumference function here:


// Code your missionDuration function here:


// Copy/paste your selectRandomEntry function here:


// Code your oxygenExpended function here:


// Candidate data & crew array.
let candidateA = {
'name':'Gordon Shumway',
'species':'alf',
'mass':90,
'o2Used':function(hrs){return 0.035*hrs},
'astronautID':414
};
let candidateB = {
'name':'Lassie',
'species':'dog',
'mass':19.1,
'o2Used':function(hrs){return 0.030*hrs},
'astronautID':503
};
let candidateC = {
'name':'Jonsey',
'species':'cat',
'mass':3.6,
'o2Used':function(hrs){return 0.022*hrs},
'astronautID':796
};
let candidateD = {
'name':'Paddington',
'species':'bear',
'mass':31.8,
'o2Used':function(hrs){return 0.047*hrs},
'astronautID':291
};
let candidateE = {
'name':'Pete',
'species':'tortoise',
'mass':417,
'o2Used':function(hrs){return 0.010*hrs},
'astronautID':599
};
let candidateF = {
'name':'Hugs',
'species':'ball python',
'mass':2.3,
'o2Used':function(hrs){return 0.018*hrs},
'astronautID':890
};

let crew = [candidateA,candidateC,candidateE];

54 changes: 54 additions & 0 deletions objects-and-math/studio/ObjectsStudio03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Code your crewMass function here:


// Code your fuelRequired function here:


// The pre-selected crew is in the array at the end of this file.
// Feel free to add, remove, or switch crew members as you see fit.

let candidateA = {
'name':'Gordon Shumway',
'species':'alf',
'mass':90,
'o2Used':function(hrs){return 0.035*hrs},
'astronautID':414
};
let candidateB = {
'name':'Lassie',
'species':'dog',
'mass':19.1,
'o2Used':function(hrs){return 0.030*hrs},
'astronautID':503
};
let candidateC = {
'name':'Jonsey',
'species':'cat',
'mass':3.6,
'o2Used':function(hrs){return 0.022*hrs},
'astronautID':796
};
let candidateD = {
'name':'Paddington',
'species':'bear',
'mass':31.8,
'o2Used':function(hrs){return 0.047*hrs},
'astronautID':291
};
let candidateE = {
'name':'Pete',
'species':'tortoise',
'mass':417,
'o2Used':function(hrs){return 0.010*hrs},
'astronautID':599
};
let candidateF = {
'name':'Hugs',
'species':'ball python',
'mass':2.3,
'o2Used':function(hrs){return 0.018*hrs},
'astronautID':890
};

let crew = [candidateB,candidateD,candidateF];

0 comments on commit 67f2c53

Please sign in to comment.