From d2a85d6717147cf042fb3a9a3924f2253b5ecf7a Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Sun, 6 Oct 2019 19:24:43 -0500 Subject: [PATCH 1/6] initial commit --- assignments/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/assignments/index.html b/assignments/index.html index 69e95d591..1669e3c5b 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -14,5 +14,6 @@

JS II - Check your work in the console!

+

Hello World!

From 8de518b597cd0484c277febc8aad2c6f9ba87571 Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Sun, 6 Oct 2019 21:53:40 -0500 Subject: [PATCH 2/6] Commit after doing callbacks.js --- assignments/callbacks.js | 29 ++++++++++++++++++++++++++++- assignments/index.html | 1 - 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/assignments/callbacks.js b/assignments/callbacks.js index cb72e70c9..29f8264bc 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -39,27 +39,54 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; */ -function getLength(arr, cb) { +function getLength (arr, cb) { // getLength passes the length of the array into the callback. + cb(arr.length); } function last(arr, cb) { // last passes the last item of the array into the callback. + cb(arr[3]); } +last(items, (lastItem) => { + console.log(lastItem); +}) + function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. + return cb(x + y); } +sumNums(3, 5, function(sumNums){ + console.log(sumNums); +}) + function multiplyNums(x, y, cb) { // multiplyNums multiplies two numbers and passes the result to the callback. + return cb(x * y); } +multiplyNums(2, 3, function(multiplyNums){ + console.log(multiplyNums); +}) + 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. + for (let i = 0; i < list.length; i++){ + if (list[i] === item){ + return cb(true); + } else { + return cb(false); + } + } } +contains('Notebook', items, function(contains){ + console.log(contains); +}) + /* STRETCH PROBLEM */ function removeDuplicates(array, cb) { diff --git a/assignments/index.html b/assignments/index.html index 1669e3c5b..69e95d591 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -14,6 +14,5 @@

JS II - Check your work in the console!

-

Hello World!

From 29cafeddd8c6f5a4b44b0df1f289813592e8ce40 Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Sun, 6 Oct 2019 22:33:19 -0500 Subject: [PATCH 3/6] commit during array-methods --- assignments/array-methods.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index f3862361e..ed8385db2 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -62,12 +62,16 @@ 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 = []; +let firstNamesAllCaps = runners.map(function(runners) { + return runners.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 = []; +let runnersLargeSizeShirt = runners.filter(() => { + return +}); console.log(runnersLargeSizeShirt); // ==== Challenge 4: Use .reduce() ==== From 90386d860166f3c703188c8f8b1bc207b68fddc6 Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Mon, 7 Oct 2019 13:55:14 -0500 Subject: [PATCH 4/6] after finishing array-methods --- assignments/array-methods.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index ed8385db2..49475697e 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -57,26 +57,41 @@ 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. +// I wasn't sure of how to do this with a .forEach() method. let fullNames = []; + +runners.forEach(runner => { + fullNames.push(`${runner.first_name} ${runner.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(function(runners) { - return runners.toUpperCase; +let firstNamesAllCaps = []; + +runners.map((runners, index) => { + firstNamesAllCaps[index] = runners.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 = runners.filter(() => { - return -}); +let runnersLargeSizeShirt = []; + +runnersLargeSizeShirt = runners.filter(runners => runners.shirt_size === 'L'); + 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; +let ticketPriceTotal = []; + +ticketPriceTotal = runners.reduce((totalValue, runners) => { + return totalValue + runners.donation; +}, 0); + console.log(ticketPriceTotal); // ==== Challenge 5: Be Creative ==== From 78f4d76c3a328955e3f69676d8f2b19f76925ea9 Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Mon, 7 Oct 2019 14:18:11 -0500 Subject: [PATCH 5/6] after finishing callbacks.js --- assignments/array-methods.js | 1 - assignments/callbacks.js | 37 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/assignments/array-methods.js b/assignments/array-methods.js index 49475697e..80fa4232c 100644 --- a/assignments/array-methods.js +++ b/assignments/array-methods.js @@ -57,7 +57,6 @@ 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. -// I wasn't sure of how to do this with a .forEach() method. let fullNames = []; runners.forEach(runner => { diff --git a/assignments/callbacks.js b/assignments/callbacks.js index 29f8264bc..bc9e22179 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -39,19 +39,23 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; */ -function getLength (arr, cb) { +//function getLength(arr, cb) { // getLength passes the length of the array into the callback. +const getLength = (arr, cb) => { cb(arr.length); -} +}; + getLength(items, length => { + console.log(`The length of the array is ${length}.`); + }); -function last(arr, cb) { +const last = (arr, cb) => { // last passes the last item of the array into the callback. - cb(arr[3]); + cb(arr[arr.length -1]) } -last(items, (lastItem) => { - console.log(lastItem); -}) +last(items, lastItem => { + console.log(`The last item in the array is ${lastItem}`); +}); function sumNums(x, y, cb) { // sumNums adds two numbers (x, y) and passes the result to the callback. @@ -67,26 +71,29 @@ function multiplyNums(x, y, cb) { return cb(x * y); } -multiplyNums(2, 3, function(multiplyNums){ +multiplyNums(6, 7, function(multiplyNums){ console.log(multiplyNums); }) 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. - for (let i = 0; i < list.length; i++){ - if (list[i] === item){ - return cb(true); - } else { - return cb(false); - } + if(list.includes(item)){ + return cb(true); + } + return cb(false); + contains(3,[1,2,3],function(success){ + if(success){ + return "true" } + return "false" + }) } - contains('Notebook', items, function(contains){ console.log(contains); }) + /* STRETCH PROBLEM */ function removeDuplicates(array, cb) { From 170ff17f54850f93244df17889d883be6ab67704 Mon Sep 17 00:00:00 2001 From: Jensen Koch Date: Mon, 7 Oct 2019 14:40:29 -0500 Subject: [PATCH 6/6] after finishing closures --- assignments/closure.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assignments/closure.js b/assignments/closure.js index 4b399c098..9b3f237e1 100644 --- a/assignments/closure.js +++ b/assignments/closure.js @@ -4,6 +4,19 @@ // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. +const dogs = () => { + let dogNumber = 0; + return function() { + dogNumber = dogNumber + 1; + return dogNumber; + } +}; + +const moreDogs = dogs(); +console.log(moreDogs()); +console.log(moreDogs()); +console.log(moreDogs()); +console.log(moreDogs()); /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */