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
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [x ] Create a forked copy of this project.
* [ x] Add your project manager as collaborator on Github.
* [x ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [x ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [x ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.
* [x ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ x] Add your project manager as a reviewer on the pull-request
* [ x] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Description

Expand All @@ -29,13 +29,16 @@

* Once you finish the exercises in each file, commit your code, and push it to your fork.

**** 1 *****

### Objects

To better understand objects, you really just need to write more of them. The [objects.js](assignments/objects.js) file contains several challenges centered around a theme of interns starting at a new job. The Human Resources team needs information about the new hires. Use your new found object skills answer vital questions for HR.

* Read the instructions found within the file carefully to finish the challenges
* Don't work on stretch until you have completed all assignments

**** 2 *****
### Arrays

The [arrays.js](assignments/arrays.js) assignment takes us through a large data set of used cars. You have been asked to help a used car business with some customer requests based on their inventory. Use for loops and arrays to solve their problems.
Expand All @@ -44,6 +47,8 @@ The [arrays.js](assignments/arrays.js) assignment takes us through a large data
* Use any array method you see fit to solve the problem
* Don't work on stretch until you have completed all assignments

**** 3 *****

### Arrow Function Syntax

* [ ] Arrow Function Syntax - [Check out this awesome guide for ES6 arrow syntax](https://medium.freecodecamp.org/when-and-why-you-should-use-es6-arrow-functions-and-when-you-shouldnt-3d851d7f0b26). You will see more and more arrow functions as you progress deeper into JavaScript. Use the [function-conversion.js](assignments/function-conversion.js) file as a helper challenge to showcase some of the differences between ES5 and ES6 syntax.
Expand Down
86 changes: 68 additions & 18 deletions assignments/arrays.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// 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},
let inventory = [
{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year":2009},
{"id":2,"car_make":"Mazda","car_model":"Miata MX-5","car_year":2001},
{"id":3,"car_make":"Land Rover","car_model":"Defender Ice Edition","car_year":2010},
{"id":4,"car_make":"Honda","car_model":"Accord","car_year":1983},
Expand Down Expand Up @@ -51,7 +54,8 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
{"id":47,"car_make":"Volkswagen","car_model":"Jetta","car_year":2007},
{"id":48,"car_make":"Dodge","car_model":"Magnum","car_year":2008},
{"id":49,"car_make":"Chrysler","car_model":"Sebring","car_year":1996},
{"id":50,"car_make":"Lincoln","car_model":"Town Car","car_year":1999}];
{"id":50,"car_make":"Lincoln","car_model":"Town Car","car_year":1999}
];


// Example for loop:
Expand All @@ -62,33 +66,79 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
// }

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


console.log("Car 33 is a " + inventory[32].car_model + " made by " + inventory[32].car_make + " and the year is " + inventory[32].car_year);

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.

This is hard coding which car and position in the array you are pointing at and it is a no-no. What if the position of that care shifted because another car has been sold?

What you want to do is iterate through each item in the array testing the id key on each object as you do, IF the id matches then you want to return that data.



//console.log("Car 33 is a" inventory[32] "*car year goes here* *car make goes here* *car model goes here*" );

// ==== 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();
// 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 = inventory.length - 1;
console.log(inventory[lastCar]);

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.

Good use of .length reduced by one to target the last item, since arrays start at 0 index and not 1


// ==== 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 = [];
console.log();
// 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 newArray = []
for (let i = 0; i < inventory.length; i++) {

newArray.push(inventory[i].car_model)
}

console.log(newArray.sort());

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 job breaking this into 2 pieces and just adding the sort to the newArray. I would take another look at more specific naming convention here though. This way it doesn't become confusing.



// ==== 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();
console.log(carYears[5])

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.

What is this?


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

for (let i = 0; i < inventory.length; i++)

if (inventory[i].car_make === "BMW" || inventory[i].car_make === "Audi")

BMWAndAudi.push(inventory[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 use of the or Logical Operator || here.

Don't forget to open and close {} after your IF conditional. Inside of that block of code is what will be executed if the if conditions are met.


console.log (BMWAndAudi.length)
console.log(BMWAndAudi);

let myJSON = JSON.stringify(BMWAndAudi);

console.log(myJSON);
36 changes: 33 additions & 3 deletions assignments/function-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,56 @@
// };
// myFunction();

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

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

let anotherFunction = (param) => {
return param;
}

console.log(anotherFunction("example"));

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

let add = (param1, param2) => {
return param1 + param2;
}

console.log(add(1,2));

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

let subtract = (param1, param2) => {
return param1 - param2;
}

console.log(subtract(1,2));


// Stretch

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

// return num * 3;

// });
// console.log(triple);

// console.log(triple);

let triple = exampleArray.map((num) => {return num * 3;});

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 job solving this one with .map. since you are using fat arrow syntax you actually don't need the brackets or the return. Fat arrow functions have what is called an implicit return. You could write the map as such

.map((num) => num * 3);

console.log(triple);
3 changes: 2 additions & 1 deletion assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<title>JS I</title>

<script src="objects.js"></script>
<script src="arrays.js"></script>
<script src="function-conversion.js"></script>
<script src="arrays.js"></script>

</head>

<body>
Expand Down
Loading