-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Ryan Walker - JavaScript-I #371
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
Open
rytwalker
wants to merge
2
commits into
bloominstituteoftechnology:master
Choose a base branch
from
rytwalker:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Let's get some practice writing a few objects for a new group of interns at a small business. | ||
|
|
||
| // ==== Challenge 1: Writing Objects ==== | ||
| // ==== Challenge 1: Writing Objects ==== | ||
| // 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: | ||
|
|
||
| // 1,mmelloy0@psu.edu,Mitzi,F | ||
|
|
@@ -11,54 +11,120 @@ | |
|
|
||
| // Example format of an intern object: 1,examples@you.edu,Example,F | ||
| const example = { | ||
| "id": 0, | ||
| "name": "Example", | ||
| "email": "examples@you.edu", | ||
| "gender": "F" | ||
| } | ||
| id: 0, | ||
| name: 'Example', | ||
| email: 'examples@you.edu', | ||
| gender: 'F' | ||
| }; | ||
|
|
||
| // Write your intern objects here: | ||
|
|
||
|
|
||
| // ==== Challenge 2: Reading Object Data ==== | ||
| 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 my name is ${this.name}`; | ||
| } | ||
| }; | ||
|
|
||
| const keven = { | ||
| id: 3, | ||
| name: 'Keven', | ||
| email: 'kmummery2@wikimedia.org', | ||
| gender: 'M' | ||
| }; | ||
|
|
||
| const gannie = { | ||
| id: 4, | ||
| name: 'Gannie', | ||
| email: 'gmartinson3@illinois.edu', | ||
| gender: 'F' | ||
| }; | ||
|
|
||
| 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 | ||
|
|
||
| // ==== Challenge 3: Object Methods ==== | ||
| 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 | ||
|
|
||
| // ==== Stretch Challenge: Nested Objects and the this keyword ==== | ||
| // ==== Stretch Challenge: Nested Objects and the this keyword ==== | ||
|
|
||
| // 1. Create a parent object with properties for name and age. Make the name Susan and the age 70. | ||
| // 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. | ||
| // 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() { | ||
| return `My name is ${this.name}`; | ||
| }, | ||
| child: { | ||
| name: 'George', | ||
| age: 50, | ||
| speak: function() { | ||
| return `My name is ${this.name}`; | ||
| }, | ||
| grandchild: { | ||
| name: 'Sam', | ||
| age: 30, | ||
| speak: function() { | ||
| return `My name is ${this.name}`; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
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. how about this pattern, since we're getting ahead of ourselves with |
||
|
|
||
| // 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 | ||
| console.log(parent.speak()); | ||
|
|
||
| // Have the child speak | ||
| console.log(parent.child.speak()); | ||
|
|
||
| // Have the grandchild speak | ||
| console.log(parent.child.grandchild.speak()); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,17 @@ | ||
| // 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 => param; | ||
|
|
||
| // let add = function (param1, param2) { | ||
| // return param1 + param2; | ||
| // }; | ||
| // add(1,2); | ||
| let add = (param1, param2) => param1 + param2; | ||
| debugger; | ||
| console.log(add(1, 2)); | ||
|
|
||
| // let subtract = function (param1, param2) { | ||
| // return param1 - param2; | ||
| // }; | ||
| // subtract(1,2); | ||
| let subtract = (param1, param2) => param1 - param2; | ||
| console.log(subtract(1, 2)); | ||
|
|
||
| // exampleArray = [1,2,3,4]; | ||
| // const triple = exampleArray.map(function (num) { | ||
| // return num * 3; | ||
| // }); | ||
| // console.log(triple); | ||
| exampleArray = [1, 2, 3, 4]; | ||
| const triple = exampleArray.map(num => num * 3); | ||
|
|
||
| console.log(triple); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice styling here