Skip to content
Open

done #860

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
87 changes: 74 additions & 13 deletions assignments/arrays.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// To help us use arrays with real world problems we are going to simulate a used car dealer that has 50 cars in their inventory.
// To help us use arrays with real world problems we are going to simulate
//a used car dealer that has 50 cars in their inventory.

// The car dealer has all of their inventory housed in the array seen below. Scroll down past the data to find out how you can help the car dealer.
// The car dealer has all of their inventory housed in the array
//seen below. Scroll down past the data to find out how you can help the car dealer.

let inventory = [
{ id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 },
Expand Down Expand Up @@ -74,31 +76,90 @@ let inventory = [
// [12, 14]

// ==== 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*`);
// 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:
for (let i = 0; i < inventory.length; i++){

if(inventory[i].id==33){
let year=inventory[i].car_year;
let model=inventory[i].car_model;
let make=inventory[i].car_make;
console.log("1. Car 33 is a " + year + " " + model + " " + make);
}

}
// ==== 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.
// 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();
function carlast(){
model=inventory[inventory.length - 1].car_model;
make=inventory[inventory.length - 1].car_make;

console.log("2. last car is " + model + ", " + make);
}

carlast();



// ==== 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
// 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




let carModels = [];
let carModelsSorted = [];
console.log();



for (let i = 0; i < inventory.length; i++){
carModels.push(inventory[i].car_model);
}
carModelsSorted = carModels.sort();


console.log(carModelsSorted);

// ==== Challenge 4 ====
// The accounting team needs all the years from every car on the lot. Create a new array from the dealer data containing only the car years and log the result in the console.
// The accounting team needs all the years from every car on the lot.
// Create a new array from the dealer data containing only the car years and log the result in the console.

let carYears = [];
console.log();

for (let i = 0; i < inventory.length; i++){
carYears.push(inventory[i].car_year);
}

console.log(carYears);

// ==== Challenge 5 ====
// The car lot manager needs to find out how many cars are older than the year 2000. Using the carYears array you just created, find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length.
// The car lot manager needs to find out how many cars are older than the year 2000.
//Using the carYears array you just created,
// find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length.
let oldCars = [];
console.log();

for (let i = 0; i < carYears.length; i++){
if(carYears[i]<2000){
oldCars.push(carYears[i]);
}
}
console.log(oldCars.length);



// ==== Challenge 6 ====
// A buyer is interested in seeing only BMW and Audi cars within the inventory. Return an array that only contains BMW and Audi cars. Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console.
let BMWAndAudi = [];
console.log();


// console.log(inventory[1].car_make);

BMWAndAudi = inventory.filter(function(a){
return a.car_make === 'BMW' || a.car_make === 'Audi' ;
}
)

console.log(BMWAndAudi);
32 changes: 16 additions & 16 deletions assignments/function-conversion.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax

// let myFunction = function () {
// console.log("Function was invoked!");
// };
// myFunction();
let myFunction = () => {
console.log("Function was invoked!");
};
myFunction();

// let anotherFunction = function (param) {
// return param;
// };
// anotherFunction("Example");
let anotherFunction = (param) =>{
return param;
};
anotherFunction("Example");

// let add = function (param1, param2) {
// return param1 + param2;
// };
// add(1,2);
let add = (param1, param2)=> {
return param1 + param2;
};
add(1,2);

// let subtract = function (param1, param2) {
// return param1 - param2;
// };
// subtract(1,2);
let subtract = (param1, param2) => {
return param1 - param2;
};
subtract(1,2);


// Stretch
Expand Down
57 changes: 55 additions & 2 deletions assignments/objects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Let's get some practice writing a few objects for a new group of interns at a small business.

// ==== 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:
// 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
// 2, kdiben1@tinypic.com, Kennan, M
Expand All @@ -19,6 +20,44 @@ const example = {

// Write your intern objects here:

const Mitzi = {
id: 1,
name: "Mitzi",
email: "mmelloy0@psu.edu",
gender: "F",
}

const Kennan = {
id: 2,
name: "Kennan",
email: "kdiben1@tinypic.com",
gender: "M",
speak: function () { return "Hello, my name is Kennan!"; },

}

const Keven = {
id: 3,
name: "Keven",
email: "kmummery2@wikimedia.org",
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",
}


// ==== Challenge 2: Reading Object Data ====
// Once your objects are created, log out the following requests from HR into the console:
Expand All @@ -33,9 +72,23 @@ const example = {

// Antonietta's Gender

console.log("Mitzi's name: "+ Mitzi.name)
console.log("Kennan's ID: "+ Kennan.id)
console.log("Keven's email: "+ Keven.email)
console.log("Gannie's name "+ Gannie.name)
console.log("Antonietta's 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());


console.log(Kennan.speak());



// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
//console.log(antonietta.multiplyNums(3,4));
Expand Down