Created
December 3, 2019 21:34
-
-
Save JasonLMoffit/e036da26abf678bdd6fcf93c5c2a8ed5 to your computer and use it in GitHub Desktop.
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
| const log = console.log; | |
| // ^ declaring & assigning variable to avoid typing out whole object.method | |
| const arr = [2, 2, 2, 2, 2]; | |
| // ^ Declaring arr and assigning it to array of numbers | |
| const sumNumbers = numbers => { | |
| // ^ fat arrow function assigned to sumNumbers decalaration | |
| let sum = 0; | |
| // ^ declaring sum and assigning it to 0 | |
| numbers.forEach(number => (sum += number)); | |
| // ^ for each item in the array of numbers add number to sum | |
| log(sum); | |
| // ^ log or return sum | |
| }; | |
| // sumNumbers(arr); | |
| // ^ executing sumNumbers, passing in the array of numbers | |
| /* | |
| Object creator | |
| In this drill, you need to write code for the createMyObject function so that it returns an object with the following key value pairs: | |
| foo => 'bar' | |
| answerToUniverse => 42 | |
| olly olly => 'oxen free' | |
| sayHello => a function that returns the string 'hello' */ | |
| const createMyObject = function() { | |
| return { | |
| foo: "bar", | |
| answerToUniverse: 42, | |
| "olly olly": "oxen free", | |
| sayHello: function() { | |
| return "hello"; | |
| } | |
| }; | |
| }; | |
| const test = createMyObject(); | |
| // log(test); | |
| /* | |
| Self-reference | |
| Modify personMaker.fullName to be a function that uses self-reference (via this) in order to return the firstName and lastName properties separated by a space. | |
| So, for instance, if firstName was 'Jane' and lastName was 'Doe', fullName() should return 'Jane Doe'. | |
| */ | |
| const personMaker = function(firstName, lastName) { | |
| log(`${firstName} ${lastName}`); | |
| }; | |
| // personMaker("Jason", "Moffit"); | |
| // personMaker("John", "Doe"); | |
| // personMaker("Jane", "Doe"); | |
| /* | |
| Take up to 10 minutes to write a function called makeStudentReport that takes a single argument, data. data is an array of objects. Each object in the array represents a student and their letter grade for a course — for example, {name: 'Johnny Robot', grade: 'C'}. | |
| makeStudentReport should return an array of strings. For each item in data, return a string that looks like this: '[name]: [grade]'. The name and grade values on the student object should be substituted in. | |
| */ | |
| const student = [ | |
| { name: "Jason", grade: "80%" }, | |
| { name: "Jack", grade: "90%" }, | |
| { name: "Jill", grade: "70%" }, | |
| { name: "Jane", grade: "75%" }, | |
| { name: "Steve", grade: "85%" } | |
| ]; | |
| const makeStudentReport = data => data.forEach(item => [log(item))]; | |
| makeStudentReport(student); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment