From 1fa29ef9b69afeab0030ced1834d7487f5e0326b Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 15 Oct 2019 13:18:01 -0700 Subject: [PATCH 1/3] finished the closure --- .vscode/settings.json | 3 +++ assignments/callbacks.js | 5 ++++- assignments/closure.js | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..abec6c783 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -41,8 +41,11 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; function getLength(arr, cb) { // getLength passes the length of the array into the callback. + return cb (arr.length); } - +getLength(items, function(length){ + console.log(length); +}); function last(arr, cb) { // last passes the last item of the array into the callback. } diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..e7519ee2d 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -3,6 +3,21 @@ // Keep it simple! Remember a closure is just a function // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. +function sayHello(greeting) { + const hello = greeting; + const name = 'Jarrod'; + console.log(`${hello}. How you doinnnn?`); + + function answer() { + const whatsup = "What's up" + const answer = "I'm doing great man!" + console.log(`${whatsup} ${name}, ${answer}`); + } + + answer(); +} + +console.log(sayHello('yo')) /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ From c91a9727058590447a2a9331a0d34ac9b9af17cd Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 15 Oct 2019 13:31:26 -0700 Subject: [PATCH 2/3] finished callbacks --- assignments/callbacks.js | 22 +++++++++++++++++++++- assignments/closure.js | 5 +++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index abec6c783..0f0da29a2 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -48,20 +48,40 @@ getLength(items, function(length){ }); function last(arr, cb) { // last passes the last item of the array into the callback. + return cb (arr[arr.length-1]); } +last(items, function(last){ + console.log(last) +}) + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + return cb (x, y); } +sumNums(4, 5, function(x , y){ + console.log(x+y); +}) function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + return cb (x,y); } - +multiplyNums(3, 4, function(x, y){ + console.log(x*y); +}) 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. + if(list.includes(item)){ + return cb(true); + } else { + return cb(false); + } } +contains('Pencil', items, function(result){ + console.log(result); +}); /* STRETCH PROBLEM */ diff --git a/assignments/closure.js b/assignments/closure.js index e7519ee2d..fe16b531c 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -14,10 +14,11 @@ function sayHello(greeting) { console.log(`${whatsup} ${name}, ${answer}`); } - answer(); +answer(); } -console.log(sayHello('yo')) +console.log(sayHello("yo")); + /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ From d6784af2eef7d41565440af13080a4cb0f32299c Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Tue, 15 Oct 2019 14:06:17 -0700 Subject: [PATCH 3/3] finished project mvp, array methods page completed --- assignments/array-methods.js | 38 +++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..8a1e1b184 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -58,28 +58,60 @@ const runners = [ // ==== 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 and populate a new array called `fullNames`. This array will contain just strings. let fullNames = []; +runners.forEach (elements =>{ + fullNames.push(`${elements.first_name} ${elements.last_name}`) +}); console.log(fullNames); // ==== Challenge 2: Use .map() ==== // The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings. let firstNamesAllCaps = []; +runners.map((Atlas, index) => { + firstNamesAllCaps[index] = Atlas.first_name.toUpperCase(); +}) console.log(firstNamesAllCaps); // ==== Challenge 3: Use .filter() ==== // The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects. let runnersLargeSizeShirt = []; +runnersLargeSizeShirt = runners.filter( largeman => { + if (largeman.shirt_size === 'L'){ + return largeman; + } + +}) console.log(runnersLargeSizeShirt); // ==== Challenge 4: Use .reduce() ==== // The donations need to be tallied up and reported for tax purposes. Add up all the donations and save the total into a ticketPriceTotal variable. let ticketPriceTotal = 0; +ticketPriceTotal = runners.reduce((totalValue, runner) => { + return totalValue + runner.donation; +}, 0); console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== // Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above. // Problem 1 - +// how to contact donators +let emails = []; +runners.forEach (elements =>{ + emails.push(`${elements.first_name} ${elements.email}`) +}); +console.log(emails); // Problem 2 - -// Problem 3 \ No newline at end of file +//top donators +let topDonors = 0; +topDonors = runners.filter(topDonator => { + if (topDonator.donation >= 200) + return topDonator.first_name +}) +console.log(topDonors); +// Problem 3 +// have to make the last name all caps if the to make names look normal +let lastName = []; +runners.map((caps, index) => { + lastName[index] = caps.last_name.toUpperCase(); +}) +console.log(lastName);