diff --git a/assignments/arrays.js b/assignments/arrays.js index 1dbf8bd35..0bc2b1c5a 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -75,30 +75,49 @@ let inventory = [ // ==== 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*`); + +//console.log("Car 33 is a " + (Object.values(inventory[32]))[3] + " " + (Object.values(inventory[32]))[1] + " " + (Object.values(inventory[32]))[2] + "." ) +console.log(inventory[33]); // ==== 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(); +let lastCar = []; +for(i = 0; i {return param}; +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 @@ -27,4 +37,7 @@ // const triple = exampleArray.map(function (num) { // return num * 3; // }); -// console.log(triple); \ No newline at end of file +// console.log(triple); +exampleArray = [1,2,3,4]; +const triple = exampleArray.map(num => num *3); +console.log(triple); diff --git a/assignments/objects.js b/assignments/objects.js index 798d5e0cf..2d82cb6b2 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -18,6 +18,44 @@ const example = { } // Write your intern objects here: +const intern1 = { + id: 1, + email: "mmelloy0@PushSubscription.edu", + firstName: "Mitzi", + gender: "F" +}; + +const intern2 = { + id: 2, + email: "kdiben1@tinypic.com", + firstName: "Kennan", + gender: 'M', + speak(){ + return `Hello my name is ${this.firstName}!`; + } +}; + +const intern3 = { + id: 3, + email: "kmummery2@wikimedia.org", + firstName: "Keven", + gender: 'M' +}; + +const intern4 = { + id: 4, + email: "gmartinson3@illinois.edu", + firstName: "Gannie", + gender: 'M' +}; + +const intern5 = { + id: 1, + email: "adaine5@samsung.com", + firstName: "Antonietta", + gender: 'F' +} + // ==== Challenge 2: Reading Object Data ==== @@ -33,12 +71,23 @@ const example = { // Antonietta's Gender +console.log(intern1.firstName); //returns Mitzi +console.log(intern2.id); //returns 2 +console.log(intern3.email); //returns kmummery2@wikimedia.org +console.log(intern4.firstName); //returns Gannie +console.log(intern5.gender); //returns F + // ==== 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("Hello, my name is " + intern2.firstName + "!"); +console.log(intern2.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)); +let multiplyNums = (a,b) => {return a*b}; + +console.log(intern5.firstName + " can multiply two numbers together as evidenced that she knows 3 multiplied by 7 = " + multiplyNums(3,7)) // === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. @@ -49,16 +98,51 @@ const 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. -const parent = {} +const parent = { + name: "Susan", -// Log the parent object's name + age: 70, -// Log the child's age +child: + {name: "George", + +age: 50, + +grandchild: + {name: "Sam", + +age: 30, + +speaks: function(){ + return this.name + " speaks!"} + + +} +, +speaks: function(){ + return this.name + " speaks!"} + +} + +, +speaks: function(){ + return this.name + " speaks!"} + + +} + + +// Log the parent object's name +console.log(parent.name); +// Log the child's age +console.log(parent.child.age); // Log the name and age of the grandchild +console.log(parent.child.grandchild) // Have the parent speak - +console.log(parent.speaks()); // Have the child speak - +console.log(parent.child.speaks()); // Have the grandchild speak +console.log(parent.child.grandchild.speaks()); \ No newline at end of file