Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions assignments/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,27 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"

// Example for loop:

// arr = [1,2,3,4];
// for (i = 0; i < arr.length; i++) {
// arr[i]; // 1,2,3,4
// }


// ==== Challenge 1 ====
// The dealer can't recall the information for a car with an id of 33 on his lot. Help the dealer find out which car has an id of 33 by logging the car's year, make, and model in the console log provided to you below:
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` );


// console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` );
// console.log(arr.id[i])
const FindCarId = CarId => {
for (i = 0; i < inventory.length; i++) {
inventory[i].id === CarId ? console.log(`Car ${CarId} is a ${inventory[i].car_year} ${inventory[i].car_make} ${inventory[i].car_model}.`) : i;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 👍

}
}
FindCarId(33);

// ==== Challenge 2 ====
// The dealer needs the information on the last car in their inventory. What is the make and model of the last car in the inventory? Log the make and model into the console.
let lastCar = 0;
console.log();

let lastCar = inventory[inventory.length-1];
console.log(`The last car in the inventory is ${lastCar.car_make} ${lastCar.car_model}.`);

// let lastCar = 0;
// console.log();

// ==== Challenge 3 ====
// The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console
Expand Down
84 changes: 72 additions & 12 deletions assignments/objects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Let's get some practice writing a few objects for a new group of interns at a small business.

// ==== Challenge 1: Writing Objects ====
// ==== Challenge 1: Writing Objects ====
// HR needs some information on the new interns put into a database. Given an id, email, first name, and gender. Create an object for each person in the company list:

// 1,mmelloy0@psu.edu,Mitzi,F
Expand All @@ -10,17 +10,47 @@
// 5,adaine5@samsung.com,Antonietta,F

// Example format of an intern object: 1,examples@you.edu,Example,F
const example = {
"id": 0,
"name": "Example",
"email": "examples@you.edu",
"gender": "F"
}
const Kennan = {
id: 2,
name: "Kennan",
email: "kdiben1@tinypic.com",
gender: "m",
speak: function() {
return `Hello, my name is ${this.name}!`;
}
};
const Mitzi = {
id: 1,
name: "Mitzi",
email: "mmelloy0@psu.edu",
gender: "F"
};
const Keven = {
id: 3,
name: "Keven",
email: "kmummery2@wikimedia",
gender: "m"
};
const Gannie = {
id: 4,
name: "Gannie",
email: "gmartinson3@illinois.edu",
gender: "m"
};
const Antonietta = {
id: 5,
name: "Antonietta",
email: "adaine5@samsung.com",
gender: "f",
multiplyNums: function(a, b) {
return a * b;
}
};
// console.log(Antonietta.multiplyNums(3,100));

// Write your intern objects here:


// ==== Challenge 2: Reading Object Data ====
// ==== Challenge 2: Reading Object Data ====
// Once your objects are created, log out the following requests from HR into the console:

// Mitzi's name
Expand All @@ -33,7 +63,9 @@ const example = {

// Antonietta's Gender

// ==== Challenge 3: Object Methods ====
// console.log("Mitzi name = "+Mitzi.name+",","Kennan id = "+Kennan.id+",","Keven email = "+Keven.email+",","Gannie name = "+Gannie.name+",","Antonietta gender = "+Antonietta.gender);

// ==== Challenge 3: Object Methods ====
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
// console.log(kennan.speak());

Expand All @@ -42,14 +74,35 @@ const example = {

// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge

// ==== Stretch Challenge: Nested Objects and the this keyword ====
// ==== Stretch Challenge: Nested Objects and the this keyword ====

// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70.
// 2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50.
// 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30
// 4. Give each of the objects the ability to speak their names using the this keyword.

const parent = {}
const parent = {
name: "Susan",
age: 70,
speak: function() {
return `Hello, my name is ${this.name}!`;
},
child: {
name: "George",
age: 50,
speak: function() {
return `Hello, my name is ${this.name}!`;
},

grandchild: {
name: "Sam",
age: 30,
speak: function() {
return `Hello, my name is ${this.name}!`;
}
}
}
};

// Log the parent object's name

Expand All @@ -62,3 +115,10 @@ const parent = {}
// Have the child speak

// Have the grandchild speak

console.log(parent.name);
console.log(parent.child.age);
console.log(parent.child.grandchild);
console.log(parent.speak());
console.log(parent.child.speak());
console.log(parent.child.grandchild.speak());