Skip to content

Commit 5d0f761

Browse files
committed
Updates to JS Fundamentals
- Updated Readme - Updated objects.js - Updated arrays.js
1 parent 64ac9c8 commit 5d0f761

File tree

3 files changed

+168
-4
lines changed

3 files changed

+168
-4
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@
77
* Fork/Clone this repository.
88
* Complete all the exercises as described inside each assignment file.
99
* Use `console.log()` statements to check to see if your code does what it is supposed to do.
10-
* To test your `console` statements you can either run `node /assignments/<fileName>` and see what prints in your terminal. You can also use an online REPL like `JSBin`, `REPL.it`, `JSFiddle` or even your `Chrome developer console`.
11-
* Once you finish the exercises in a file, commit your code, and push it to your fork.
12-
* Once your assignments are logging out the expected output, and you've
10+
* To test your `console` statements you can either run `node /assignments/<fileName>` and see what prints in your terminal. You can also use an online tool like `JSBin`, `REPL.it`, `JSFiddle` or even your `Chrome developer console`.
11+
* Once you finish the exercises in each file, commit your code, and push it to your fork.
12+
13+
### Objects
14+
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.
15+
16+
* Read the instructions found within the file carefully to finish the challenges.
17+
* Complete each challenge presented before moving on to Arrays.
18+
19+
### Arrays
20+
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.
21+
22+
* Utilize the the array `inventory` to complete your challenges
23+
* You can't use map, reduce, or filter to solve these problems. Only use native JavaScript for loops.
24+
* Complete each challenge presented before moving on to Callbacks.
1325

1426
### Callbacks
1527

16-
* In this file you'll be receiving a lot of training on how to use callbacks to pass around data.
28+
* In the [callbacks.js](assignments/callbacks.js) file you'll be receiving a lot of practice on how to use callbacks to pass around data.
1729
* Write out each function using the `ES5` `function` keyword syntax.
1830
* Remember that a callback function is simply a function that is being passed around to other functions.
1931
* **Stretch Problem** After you're done with all of the functions, go ahead and re-factor all of them to use `ES6` `Arrow Functions`

assignments/arrays.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// 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.
2+
3+
// 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.
4+
5+
let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year":2009},
6+
{"id":2,"car_make":"Mazda","car_model":"Miata MX-5","car_year":2001},
7+
{"id":3,"car_make":"Land Rover","car_model":"Defender Ice Edition","car_year":2010},
8+
{"id":4,"car_make":"Honda","car_model":"Accord","car_year":1983},
9+
{"id":5,"car_make":"Mitsubishi","car_model":"Galant","car_year":1990},
10+
{"id":6,"car_make":"Audi","car_model":"riolet","car_year":1995},
11+
{"id":7,"car_make":"Smart","car_model":"Fortwo","car_year":2009},
12+
{"id":8,"car_make":"Audi","car_model":"4000CS Quattro","car_year":1987},
13+
{"id":9,"car_make":"Ford","car_model":"Windstar","car_year":1996},
14+
{"id":10,"car_make":"Mercedes-Benz","car_model":"E-Class","car_year":2000},
15+
{"id":11,"car_make":"Infiniti","car_model":"G35","car_year":2004},
16+
{"id":12,"car_make":"Lotus","car_model":"Esprit","car_year":2004},
17+
{"id":13,"car_make":"Chevrolet","car_model":"Cavalier","car_year":1997},
18+
{"id":14,"car_make":"Dodge","car_model":"Ram Van 1500","car_year":1999},
19+
{"id":15,"car_make":"Dodge","car_model":"Intrepid","car_year":2000},
20+
{"id":16,"car_make":"Mitsubishi","car_model":"Montero Sport","car_year":2001},
21+
{"id":17,"car_make":"Buick","car_model":"Skylark","car_year":1987},
22+
{"id":18,"car_make":"Geo","car_model":"Prizm","car_year":1995},
23+
{"id":19,"car_make":"Oldsmobile","car_model":"Bravada","car_year":1994},
24+
{"id":20,"car_make":"Mazda","car_model":"Familia","car_year":1985},
25+
{"id":21,"car_make":"Chevrolet","car_model":"Express 1500","car_year":2003},
26+
{"id":22,"car_make":"Jeep","car_model":"Wrangler","car_year":1997},
27+
{"id":23,"car_make":"Eagle","car_model":"Talon","car_year":1992},
28+
{"id":24,"car_make":"Toyota","car_model":"MR2","car_year":2003},
29+
{"id":25,"car_make":"BMW","car_model":"525","car_year":2005},
30+
{"id":26,"car_make":"Cadillac","car_model":"Escalade","car_year":2005},
31+
{"id":27,"car_make":"Infiniti","car_model":"Q","car_year":2000},
32+
{"id":28,"car_make":"Suzuki","car_model":"Aerio","car_year":2005},
33+
{"id":29,"car_make":"Mercury","car_model":"Topaz","car_year":1993},
34+
{"id":30,"car_make":"BMW","car_model":"6 Series","car_year":2010},
35+
{"id":31,"car_make":"Pontiac","car_model":"GTO","car_year":1964},
36+
{"id":32,"car_make":"Dodge","car_model":"Ram Van 3500","car_year":1999},
37+
{"id":33,"car_make":"Jeep","car_model":"Wrangler","car_year":2011},
38+
{"id":34,"car_make":"Ford","car_model":"Escort","car_year":1991},
39+
{"id":35,"car_make":"Chrysler","car_model":"300M","car_year":2000},
40+
{"id":36,"car_make":"Volvo","car_model":"XC70","car_year":2003},
41+
{"id":37,"car_make":"Oldsmobile","car_model":"LSS","car_year":1997},
42+
{"id":38,"car_make":"Toyota","car_model":"Camry","car_year":1992},
43+
{"id":39,"car_make":"Ford","car_model":"Econoline E250","car_year":1998},
44+
{"id":40,"car_make":"Lotus","car_model":"Evora","car_year":2012},
45+
{"id":41,"car_make":"Ford","car_model":"Mustang","car_year":1965},
46+
{"id":42,"car_make":"GMC","car_model":"Yukon","car_year":1996},
47+
{"id":43,"car_make":"Mercedes-Benz","car_model":"R-Class","car_year":2009},
48+
{"id":44,"car_make":"Audi","car_model":"Q7","car_year":2012},
49+
{"id":45,"car_make":"Audi","car_model":"TT","car_year":2008},
50+
{"id":46,"car_make":"Oldsmobile","car_model":"Ciera","car_year":1995},
51+
{"id":47,"car_make":"Volkswagen","car_model":"Jetta","car_year":2007},
52+
{"id":48,"car_make":"Dodge","car_model":"Magnum","car_year":2008},
53+
{"id":49,"car_make":"Chrysler","car_model":"Sebring","car_year":1996},
54+
{"id":50,"car_make":"Lincoln","car_model":"Town Car","car_year":1999}];
55+
56+
// PROJECT RESTRICTION: You can't use map, reduce, or filter to solve these problems. Only use native JavaScript for loops.
57+
58+
// Example for loop:
59+
// arr = [1,2,3,4];
60+
// for (i = 0; i < arr.length; i++) {
61+
// arr[i]; // 1,2,3,4
62+
// }
63+
64+
//========= 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 that is by logging the car's year, make, and model in the console.
65+
console.log();
66+
67+
//========= 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.
68+
let lastCar = 0;
69+
console.log();
70+
71+
//========= 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
72+
let carModels = [];
73+
console.log();
74+
75+
//========= 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.
76+
let carYears = [];
77+
console.log();
78+
79+
//========= 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.
80+
let oldCars =[];
81+
console.log();
82+
83+
//========= 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.
84+
let BMWAndAudi =[];
85+
console.log();
86+
87+
88+

assignments/objects.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Let's get some practice writing a few objects for a new group of interns at a small business.
2+
3+
// ==== Challenge 1: Writing Objects ====
4+
// 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:
5+
6+
// 1,[email protected],Mitzi,F
7+
// 2,[email protected],Kennan,M
8+
// 3,[email protected],Keven,M
9+
// 4,[email protected],Gannie,M
10+
// 5,[email protected],Antonietta,F
11+
12+
// Example format of an intern object: 1,[email protected],Example,F
13+
let example = {
14+
"id": 0,
15+
"name": "Example",
16+
"email": "[email protected]",
17+
"gender": "F"
18+
}
19+
20+
// Write your intern objects here:
21+
22+
23+
// ==== Challenge 2: Reading Object Data ====
24+
// Once your objects are created, log out the following requests from HR into the console:
25+
26+
// Mitzi's name
27+
28+
// Kenna's ID
29+
30+
// Keven's email
31+
32+
// Gannie's name
33+
34+
// Antonietta's Gender
35+
36+
// ==== Challenge 3: Object Methods ====
37+
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
38+
// console.log(kennan.speak());
39+
40+
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
41+
//console.log(antonietta.multiplyNums(3,4));
42+
43+
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
44+
45+
// ==== Stretch Challenge: Nested Objects and the this keyword ====
46+
47+
// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70.
48+
// 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.
49+
// 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
50+
// 4. Give each of the objects the ability to speak their names using the this keyword.
51+
52+
let parent = {}
53+
54+
// Log the parent object's name
55+
56+
// Log the child's age
57+
58+
// Log the name and age of the grandchild
59+
60+
// Have the parent speak
61+
62+
// Have the child speak
63+
64+
// Have the grandchild speak

0 commit comments

Comments
 (0)