diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f692c35c6..0700c7a44 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -55,7 +55,10 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c // ==== Challenge 1: Use .forEach() ==== // The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName. -let fullName = []; +let fullName = runners["first_name", "last_name"]; +//fullName.forEach(function(element) { + +//}) console.log(fullName); // ==== Challenge 2: Use .map() ==== diff --git a/assignments/callbacks.js b/assignments/callbacks.js index c1c013800..5e8be4e16 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -1,6 +1,6 @@ // Create a higher order function and invoke the callback function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems. -const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; +const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum',]; /* @@ -27,20 +27,42 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { // getLength passes the length of the array into the callback. + cb(items.length); + console.log(getLength); } +// console.log(`The Length is: ${items.length}`); +// } +// getLength(); +const cb = x => { + console.log("Last item is: ", x); + return x; +} function last(arr, cb) { // last passes the last item of the array into the callback. + return cb(arr[items.length - 1]); } +last(items, cb); + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + cb(x + y); } +sumNums(7, 7, answer => { + console.log(`The Answer is: ${answer}.`) +}) + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + cb(x * y); } +multiplyNums(7, 7, answer => { + console.log(`The answer is: ${answer}.`) +}) + 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. diff --git a/assignments/closure.js b/assignments/closure.js index 4307524fc..620eed78a 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -1,7 +1,12 @@ // ==== Challenge 1: Write your own closure ==== // Write a simple closure of your own creation. Keep it simple! +const minXpReached = "Level Up!" +function levelUp() { + alert(minXpReached); +} +//levelUp(); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */