diff --git a/assignments/arrays.js b/assignments/arrays.js index c007f3e99..e5caf08f6 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -63,34 +63,57 @@ 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*` ); + +for (i=0;i {console.log(item)}) + + function getLength(arr, cb) { // getLength passes the length of the array into the callback. + cb(arr.length); } +getLength(items, length => {console.log(length)}) + function last(arr, cb) { // last passes the last item of the array into the callback. + cb(arr[arr.length-1]); } +last(items, length => {console.log(length)}) + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + cb(x+y); } +sumNums(2,4,sum => {console.log(sum)}) + + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + cb(x*y); } +multiplyNums(2,4,m => {console.log(m)}) + function contains(item, list, cb) { // contains checks if an item is present inside of the given array/list. // Pass true to the callback if it is, otherwise pass false. + cb((list.indexOf(item) === -1) ? false : true); } +contains('Pencil',items, c => {console.log(c)}) /* STRETCH PROBLEM */ @@ -31,4 +50,11 @@ function removeDuplicates(array, cb) { // removeDuplicates removes all duplicate values from the given array. // Pass the duplicate free array to the callback function. // Do not mutate the original array. + let rd = array.filter(function(item, pos,arr) { + return arr.indexOf(item) == pos; + }) + + cb(rd); } + +removeDuplicates([1,2,1,2,3,4],c => {console.log(c)}) diff --git a/assignments/objects.js b/assignments/objects.js index 04399eda9..d7ff64ad6 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -18,27 +18,48 @@ let example = { } // Write your intern objects here: +function Intern(id, email, name, gender){ + this.id = id; + this.email = email; + this.name = name; + this.gender = gender; +} + +let mitzi = new Intern(1,'mmelloy0@psu.edu','Mitzi','F'); +let kennan = new Intern(2,'kdiben1@tinypic.com','Kennan','M'); +let keven = new Intern(3,'kmummery2@wikimedia.org','Keven','M'); +let gannie = new Intern(4,'gmartinson3@illinois.edu','Gannie','M'); +let antonietta = new Intern(5,'adaine5@samsung.com','Antonietta','F'); // ==== Challenge 2: Reading Object Data ==== // Once your objects are created, log out the following requests from HR into the console: // Mitzi's name - +console.log(mitzi.name); // Kennan's ID - +console.log(kennan.id); // Keven's email - +console.log(keven.email); // Gannie's name - +console.log(gannie.name); // Antonietta's Gender +console.log(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()); + +kennan.speak = function(){ + return "Hello, my name is" + this.name; +} +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)); +antonietta.multiplyNums = function(a,b){ + return a*b; +} +console.log(antonietta.multiplyNums(3,4)); // === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge @@ -49,16 +70,34 @@ let example = { // 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. -let parent = {} +let parent = { + name: 'Susan', + age: 70, + child: { + name: 'George', + age:50, + child:{ + name:"Sam", + age:30, + speak: function(){return "My Name is " + this.name;} + }, + speak: function(){return "My Name is " + this.name;} + }, + speak: function(){return "My Name is " + this.name;} +} // Log the parent object's name - +console.log(parent.name); // Log the child's age +console.log(parent.child.name); // Log the name and age of the grandchild +console.log(parent.child.child.name); +console.log(parent.child.child.age); // Have the parent speak - +console.log(parent.speak()); // Have the child speak - +console.log(parent.child.speak()); // Have the grandchild speak +console.log(parent.child.child.speak()); \ No newline at end of file