Repository navigation
JavaScript-I by Edgar Flores #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,26 +19,72 @@ const example = { | |||||
|
|
||||||
| // Write your intern objects here: | ||||||
|
|
||||||
| const mitzi = { | ||||||
| "id": 1, | ||||||
| "name": "Mitzi", | ||||||
| "email": "mmelloy0@psu.edu", | ||||||
| "gender": "F" | ||||||
| } | ||||||
|
|
||||||
| const kennan = { | ||||||
| "id": 2, | ||||||
| "name": "Kennan", | ||||||
| "email": "kdiben1@tinypic.com", | ||||||
| "gender": "M", | ||||||
| "speak": function () { | ||||||
| return "Hello I'm Kennan"; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const keven = { | ||||||
| "id": 3, | ||||||
| "name": "Keven", | ||||||
| "email": "kmummery2@wikimedia.org", | ||||||
| "gender": "M" | ||||||
| } | ||||||
|
|
||||||
| const gannie = { | ||||||
| "id": 4, | ||||||
| "name": "Gannie", | ||||||
| "email": "gmartison3@illinois.edu", | ||||||
| "gender": "M" | ||||||
| } | ||||||
|
|
||||||
| const antonietta = { | ||||||
| "id": 5, | ||||||
| "name": "Antonietta", | ||||||
| "email": "adaine5@samsung.com", | ||||||
| "gender": "F", | ||||||
| "multiplyNums": function (num1, num2) { | ||||||
| return num1 * num2; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| // ==== 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()); | ||||||
| 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)); | ||||||
| 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 +95,42 @@ 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', | ||||||
| age: 70, | ||||||
| speak: function() { | ||||||
| console.log("Hello I'm", this.name); | ||||||
| }, | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| child: { | ||||||
| name: 'George', | ||||||
| age: 50, | ||||||
| speak: function() { | ||||||
| console.log("Hello I'm", this.name); | ||||||
| }, | ||||||
| grandchild: { | ||||||
| name: 'Sam', | ||||||
| age: 30, | ||||||
| speak: function() { | ||||||
| console.log("Hello I'm", this.name); | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 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.name, parent.child.grandchild.age); | ||||||
|
|
||||||
| // Have the parent speak | ||||||
| parent.speak(); | ||||||
|
|
||||||
| // Have the child speak | ||||||
| parent.child.speak(); | ||||||
|
|
||||||
| // Have the grandchild speak | ||||||
| parent.child.grandchild.speak(); | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,23 +1,32 @@ | ||||||||
| // Take the commented ES5 syntax and convert it to ES6 arrow Syntax | ||||||||
|
|
||||||||
| // let myFunction = function () {}; | ||||||||
| let myFunction = () => {}; | ||||||||
|
|
||||||||
| // let anotherFunction = function (param) { | ||||||||
| // return param; | ||||||||
| // }; | ||||||||
|
|
||||||||
| let anotherFunction = param => {return param}; | ||||||||
|
|
||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can leave the braces off here and it'll still return the value of param |
||||||||
| // let add = function (param1, param2) { | ||||||||
| // return param1 + param2; | ||||||||
| // }; | ||||||||
| // add(1,2); | ||||||||
|
|
||||||||
| let add = (param1, param2) => {return param1 + param2}; | ||||||||
| add(1, 2); | ||||||||
|
|
||||||||
| // let subtract = function (param1, param2) { | ||||||||
| // return param1 - param2; | ||||||||
| // }; | ||||||||
| // subtract(1,2); | ||||||||
|
|
||||||||
| let subtract = (param1, param2) => {return param1 + param2}; | ||||||||
| subtract(1, 2); | ||||||||
|
|
||||||||
| // exampleArray = [1,2,3,4]; | ||||||||
| // const triple = exampleArray.map(function (num) { | ||||||||
| // return num * 3; | ||||||||
| // }); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| // console.log(triple); | ||||||||
| // console.log(triple); | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using template literals.