forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LaunchCodeEducation#11 from LaunchCodeEducation/ch…
…-12-objects Chapter 12: Objects and the Math Object
- Loading branch information
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
|