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
166 changes: 16 additions & 150 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 42 additions & 7 deletions assignments/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"


// Example for loop:

// arr = [1,2,3,4];
// for (let i = 0; i < arr.length; i++) {
// arr[i]; // 1,2,3,4
// }
let audi = inventory.filter(inventory => {return inventory.car_make === "Audi"});
let dodge = inventory.filter(inventory => {return inventory.car_make === "Dodge"});


// ==== 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*` );

let carThirtyThree = inventory[32];

console.log(carThirtyThree);
//for loop, then block that has if statement that says if inventory[i] === [32] return 'This vehicle is a ' + this.car_year + this.car_make + this.car_model + 'and is car number' + this.id + ' on our lot today';

carThirtyThree.description = function(){
return 'This vehicle is a ' + this.car_year + this.car_make + this.car_model + 'and is car number' + this.id + ' on our lot today';
Expand All @@ -83,35 +85,68 @@ console.log(lastCar.car_make + lastCar.car_model);

// ==== 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
let carModels = []; /*so, what I believe that I need to do here is sort the current array but the only property I want is the car model property and I want to push that into a new array, that empty array is sitting here. I don't know what the solution looks like syntactically.*/
let carModels = []; /*So, the car models need to be sorted alphabetically and then that sorting order needs to be pushed into the empty array sitting here. I'm not sure what that last step looks like syntactically*/
for (let i = 0; i < inventory.length; i++) {
let currentCarModel = inventory[i].car_model; //what Derrick did is he created a variable, extracted the information and placed that information in the variable, and then pushed the variable into the empty array.
carModels.push(currentCarModel);
// carModels.push(inventory[i].car_model);
}
carModels.sort();

console.log(carModels);

console.log();
//https://www.w3schools.com/js/js_array_sort.asp
//https://www.sitepoint.com/sort-an-array-of-objects-in-javascript/
//http://javascriptkit.com/javatutors/arraysort2.shtml
/* cars.sort(function(a, b){
var x = a.type.toLowerCase();
var y = b.type.toLowerCase();
if (x < y) {return -1;}
if (x > y) {return 1;}
return 0;
}); */
});git add .
employees.sort(function(a, b){
var nameA=a.name.toLowerCase(), nameB=b.name.toLowerCase()
if (nameA < nameB) //sort string ascending
return -1
if (nameA > nameB)
return 1
return 0 //default return value (no sorting)
})
*/


// ==== 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.
let carYears = []; /*Again, empty array to sort the model years into, I don't know what the solution looks like syntactically*/
console.log();
inventory.forEach(element => carYears.push(element.car_year))//concise arrow, for each element in the array, the element is the parameter, and we pushed the car year property of each element in the inventory array up into the empty array of car years*/

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.
let oldCars = [];
console.log();
for (let i = 0; i < carYears.length; i++){
if (carYears[i] < 2000) {
oldCars.push(carYears[i])
}
}//so, this is not as concise as the one below, again with the concise body the oldCars can equal the array of carYears using the built in filter method to sift out the elements of the array that meet the older than the year 2000 criteria.

let oldCars2 = carYears.filter(element => element < 2000)
console.log(oldCars2.length);

console.log(oldCars2);

console.log(oldCars);

// ==== 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();


//let stringify = JSON.stringify(BMWAndAudi);
//
// console.log(stringify)
//So, what exactly is the json. , why are we using the word and here? this is really concise, better than a for loop and it accomplishes the same thing in less code*/

3 changes: 1 addition & 2 deletions assignments/function-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ subtract(1100,500);

// exampleArray = [1,2,3,4];
// const triple = exampleArray.map(function (num) {
// return num * 3;
// return num * 3;
// });
// console.log(triple);

28 changes: 27 additions & 1 deletion assignments/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,42 @@ console.log(antonietta.multiplyNums(8,67));
// 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 = {}
let parent = new Object(){
parent.name = "Susan";
parent.age = 70;
parent.speak = function(){
return 'Hello, my name is ' + this.name + 'and I am ' + this.age + 'years old.'
};
let child = new Object(){
child.name = "George";
child.age = 50;
child.speak = function(){
return 'Hello, my name is ' + this.name + 'and I am ' + this.age + 'years old.'
};
let grandchild = new Object(){
grandchild.name = "Sam";
grandchild.age = 30;
grandchild.speak = function(){
return 'Hello, my name is ' + this.name + 'and I am ' + this.age + 'years old.'
};
}
}
}//why did we make these nested objects? I mean, they look pretty but what was the objective.

// Log the parent object's name
console.log(parent.name);

// Log the child's age
console.log(child.age);

// Log the name and age of the grandchild
console.log(grandchild.name + grandchild.age);

// Have the parent speak
console.log(parent.speak());

// Have the child speak
console.log(child.speak());

// Have the grandchild speak
console.log(grandchild.speak());