Skip to content

Commit

Permalink
Objects exercises done
Browse files Browse the repository at this point in the history
  • Loading branch information
craigb28 committed Feb 1, 2024
1 parent c5946a1 commit 776c3e9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
6 changes: 6 additions & 0 deletions objects-and-math/chapter-examples/ForInLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ let tortoiseOne = {
age: 85,
diet: ["pumpkins", "lettuce", "cabbage"]
};
// birthday: function () {age=this.age+1;
// return age}


for (item in tortoiseOne) {
console.log(item+": "+tortoiseOne[item])
}
// Using a for..in loop, iterate through each property in the tortoiseOne object and print the value to the console.
2 changes: 1 addition & 1 deletion objects-and-math/chapter-examples/KindnessSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function randomSelection(arr){
let words = ['Hello', 'World', 'Python', 'JavaScript', 'Rutabaga'];

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

//Experiment with the code above. Try to:
Expand Down
55 changes: 52 additions & 3 deletions objects-and-math/exercises/ObjectExercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,70 @@ let superChimpOne = {
name: "Chad",
species: "Chimpanzee",
mass: 9,
age: 6
age: 6,
astronautID: 1,
move: function() {return Math.floor(Math.random()*11)}
};

let salamander = {
name: "Lacey",
species: "Axolotl Salamander",
mass: 0.1,
age: 5
age: 5,
astronautID: 2,
move: function() {return Math.floor(Math.random()*11)}
};

let superChimpTwo = {
name: "Brad",
species: "Chimpanzee",
mass: 11,
age: 6,
astronautID: 3,
move: function() {return Math.floor(Math.random()*11)}
};

let beagle = {
name: "Leroy",
species: "Beagle",
mass: 14,
age: 5,
astronautID: 4,
move: function() {return Math.floor(Math.random()*11)}
};

let tardigrade = {
name: "Almina",
species: "Tardigrade",
mass: 0.0000000001,
age: 1,
astronautID: 5,
move: function() {return Math.floor(Math.random()*11)}
};

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

// Create an array to hold the animal objects.

let crewArray = [superChimpOne, salamander, superChimpTwo, beagle, tardigrade]

// console.log()

// Print out the relevant information about each animal.

// Start an animal race!
function crewReports(animalObject){
return `${animalObject.name} is a ${animalObject.species}. They are ${animalObject.age} years old and ${animalObject.mass} kilograms. Their ID is ${animalObject.astronautID}.`
};

for (let i=0; i<crewArray.length; i++){
console.log(crewArray[i]);
};


// Start an animal race!

function fitnessTest(arr){
let turnsToFinishRace = [];
for (let i=0)
return turnsToFinishRace;
}

0 comments on commit 776c3e9

Please sign in to comment.