From 9b066457e7cd2650fefc8d5c45a64c9cd3d39366 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 24 Oct 2017 18:54:01 -0500 Subject: [PATCH 01/11] starting to understand the syntax of forEach --- 04week/gitOlympics.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 04week/gitOlympics.js diff --git a/04week/gitOlympics.js b/04week/gitOlympics.js new file mode 100644 index 000000000..9554111a9 --- /dev/null +++ b/04week/gitOlympics.js @@ -0,0 +1,7 @@ +'use strict' + +const names = ['athens', 'berlin', 'atlanta', 'seoul'] + +printListOfOlympics=(arr)=>{ + arr.forEach(i)=>{console.log(i)} +} From 01da0422d27d6637f825cad78c5506bf8012a2f1 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 24 Oct 2017 18:56:26 -0500 Subject: [PATCH 02/11] added missing const --- 04week/gitOlympics.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04week/gitOlympics.js b/04week/gitOlympics.js index 9554111a9..fe9b8488c 100644 --- a/04week/gitOlympics.js +++ b/04week/gitOlympics.js @@ -2,6 +2,8 @@ const names = ['athens', 'berlin', 'atlanta', 'seoul'] -printListOfOlympics=(arr)=>{ - arr.forEach(i)=>{console.log(i)} +const printListOfOlympics=(arr)=>{ + arr.forEach(i => console.log(i)) } + +printListOfOlympics(names); From 7d6c86886eae7e51532acba7f969c21f1cc58090 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 24 Oct 2017 18:57:02 -0500 Subject: [PATCH 03/11] added one more city --- 04week/gitOlympics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04week/gitOlympics.js b/04week/gitOlympics.js index fe9b8488c..332de72b7 100644 --- a/04week/gitOlympics.js +++ b/04week/gitOlympics.js @@ -1,6 +1,6 @@ 'use strict' -const names = ['athens', 'berlin', 'atlanta', 'seoul'] +const names = ['athens', 'berlin', 'atlanta', 'seoul', 'los angeles'] const printListOfOlympics=(arr)=>{ arr.forEach(i => console.log(i)) From 26d8d99a53cd2028cf579cd17cf515b09fc2ea2b Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 24 Oct 2017 19:51:37 -0500 Subject: [PATCH 04/11] will review this change in a bit --- 01week/datatypes.js | 81 +++++++++++++++++++++++++++++++++++++++++++++ 02week/pigLatin.js | 51 ---------------------------- 02week/tests.js | 67 +++++++++++++++++++++++++++++++++++++ index.html | 2 +- 4 files changed, 149 insertions(+), 52 deletions(-) delete mode 100644 02week/pigLatin.js diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..9f82f4110 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,81 @@ +`use strict` + +//returns current date and time +//create a function that inputs the year, month, and day +//make new var to store the today var and toDateString method +//use var today with toDateString method + +function dateDisplay(year, month, date) { + var today = new Date(year, month, date); + return today.toDateString(); +} + +dateDisplay(1985, 10, 1); + +//create a function with one argument. +//the argument should be a number +//return the argument with the toString() method to make the number a string + +function toNumber(number) { + return number.toString() +} + +toNumber(13); + +//create a fucntion that receives one argument +//argument should be a string +//use parseInt() method on argument to pull a number out + +function stringNum(str){ + return parseInt(str); +} + +stringNum('15 years'); + +//create a function with one argument +//use the typeOf method on the argument and return the result + +function dataType(dT){ + return typeof(dT); +} + +dataType(`words words words`); + +//Create a function with two arguments +//Inside the function, add the two var together +//Use parseInt() to take the number out of the string + +function add(numOne, numTwo) { + return parseInt(numOne) + parseInt(numTwo) +} + +add(`13`, `17`); + +//write a function that returns a true if two var are truthy +//if both var are true, show "nope" +//if both var are false, also show "nope" +// if one is false and one is true, show "yep!" + +function truest(thingOne, thingTwo) { + if ((thingOne === true && thingTwo === true) || (thingOne === false && thingTwo === false)){ + return `nope`; + } else { + return 'yep!'; + } +} + +truest(true, false); + +//write a function with two arguments +//if both arguments are false, show a confirmation message +//if either argument is true, return a negative response + +function womp(dumb, dumber) { + if (dumb === false && dumber === false) { + return `yes, they're both false` + } else { + return 'nah, try again' + } +}; + +womp(false, true); diff --git a/02week/pigLatin.js b/02week/pigLatin.js deleted file mode 100644 index 046434c94..000000000 --- a/02week/pigLatin.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const readline = require('readline'); -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - - -function pigLatin(word) { - - // Your code here - -} - - -function getPrompt() { - rl.question('word ', (answer) => { - console.log( pigLatin(answer) ); - getPrompt(); - }); -} - -// Tests - -if (typeof describe === 'function') { - - describe('#pigLatin()', () => { - it('should translate a simple word', () => { - assert.equal(pigLatin('car'), 'arcay'); - assert.equal(pigLatin('dog'), 'ogday'); - }); - it('should translate a complex word', () => { - assert.equal(pigLatin('create'), 'eatecray'); - assert.equal(pigLatin('valley'), 'alleyvay'); - }); - it('should attach "yay" if word begins with vowel', () => { - assert.equal(pigLatin('egg'), 'eggyay'); - assert.equal(pigLatin('emission'), 'emissionyay'); - }); - it('should lowercase and trim word before translation', () => { - assert.equal(pigLatin('HeLlO '), 'ellohay'); - assert.equal(pigLatin(' RoCkEt'), 'ocketray'); - }); - }); -} else { - - getPrompt(); - -} diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..6991b4d89 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -0,0 +1,67 @@ +'use strict'; + +const assert = require('assert'); +const readline = require('readline'); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + + +function rockPaperScissors(hand1, hand2) { + // check for a tie, if it is a tie, return tie, if not check for win + // rock beats scissors, scissors beats paper, paper beats rock + //to find who won, compare hand1 to hand2 + const handOne = 'Hand one wins!' + const handTwo = 'Hand two wins!' + + if(hand1 === hand2) { + return "It's a tie!"; + } else if (hand1 === 'rock'){ + return hand2 === 'paper' ? handTwo : handOne; + } else if (hand1 === 'paper') { + return hand2 === 'scissors' ? handTwo : handOne; + } else if (hand1 === 'scissors') { + return hand2 === 'rock' ? handTwo : handOne; + } +}; + +function getPrompt() { + rl.question('hand1: ', (answer1) => { + rl.question('hand2: ', (answer2) => { + console.log( rockPaperScissors(answer1, answer2) ); + getPrompt(); + }); + }); +} + +// Tests + +if (typeof describe === 'function') { + + describe('#rockPaperScissors()', () => { + it('should detect a tie', () => { + assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); + assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!"); + assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!"); + }); + it('should detect which hand won', () => { + assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!"); + assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); + assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!"); + assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!"); + assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); + assert.equal(rockPaperScissors('paper', 'rock'), "Hand one wins!"); + }); + it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { + assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); + assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); + assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); + });w + // it('should detect ') + }); +} else { + + getPrompt(); + +} diff --git a/index.html b/index.html index a8de93e90..ffe101bd4 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,6 @@ -

Hello World!

+

Hello Eric, how are you!

From 3cba5e462dab530032146ce3ea73f8a3ab1fae3e Mon Sep 17 00:00:00 2001 From: walzer85 Date: Wed, 8 Nov 2017 20:54:18 -0600 Subject: [PATCH 05/11] first two problems in --- 06week/higherOrder.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index 73926e3dc..a1089fb5a 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -3,11 +3,30 @@ const assert = require('assert'); function forEach(arr, callback) { - // Your code here + // create an array with whatever you want in it + const arrProblemOne = ['Eric', 'Eric', 'Eric', 'I promise I am not vain. Seriously'] + + //make a for loop that runs the number of items in the array amount of times. + //make a variable that prints a phrase the amount of times defined by the for loop + for (let i = 0; i < arrProblemOne.length; i++) { + const printTheArrayLength = () => { + console.log('Over and over!'); + } + } } function map(arr, callback) { - // Your code here + // Create an array, put whatever you want in it + const test = ['1', '2', '3', '4', '5', '6']; + + //doThis(), a function that creates a new array, then for each item in the original array, and does + const doThis = (arr, callBackFunction) => { + const newArr = []; + arr.forEach((i) => { + newArr.push(callBackFunction(i)); + }); + return newArr; +}; } function filter(arr, callback) { From 537595649469bff005800050106674101336ffc5 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 06:22:41 -0600 Subject: [PATCH 06/11] added description of filter function --- 06week/higherOrder.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index a1089fb5a..ca70a1769 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -19,13 +19,15 @@ function map(arr, callback) { // Create an array, put whatever you want in it const test = ['1', '2', '3', '4', '5', '6']; - //doThis(), a function that creates a new array, then for each item in the original array, and does + //doThis(), a function that creates a new array, then does whatever function you want when you call doThis to the original array + //pushes the result of the called function to the new array + //print out the new array const doThis = (arr, callBackFunction) => { const newArr = []; arr.forEach((i) => { newArr.push(callBackFunction(i)); }); - return newArr; + console.log(newArr); }; } From b3a48ddadb8039cb921c52c3a8acfe8f3549d46f Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 06:39:21 -0600 Subject: [PATCH 07/11] figuring out the filter function --- 06week/higherOrder.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index ca70a1769..620df661d 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -32,7 +32,17 @@ function map(arr, callback) { } function filter(arr, callback) { - // Your code here + //create an array with three numbers + const arrProblemThree = [1, 2, 3]; + + //longestWords(), create a function that takes an array and a function + //the called function affects the called array + //a new, empty array accepts the results of the function + const longestWords = (arrTwo, callbackTwo) => { + const arrResultThree = []; + if () + } + } } function some(arr, callback) { From 56f57e6aad8f5b7d23571fd65bae7d4e1f76f94f Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 17:58:56 -0600 Subject: [PATCH 08/11] ready to push? --- 06week/higherOrder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index 620df661d..df578a633 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -38,11 +38,11 @@ function filter(arr, callback) { //longestWords(), create a function that takes an array and a function //the called function affects the called array //a new, empty array accepts the results of the function - const longestWords = (arrTwo, callbackTwo) => { + const filtered = (arrTwo, callbackTwo) => { const arrResultThree = []; - if () + if (callbackTwo(arrTwo[i])) arrResultThree.push(arrTwo[i]) } - } + console.log(arrResultThree); } function some(arr, callback) { From 19f4399daab1e6840c56f4348fd7fae1397770d7 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 18:01:35 -0600 Subject: [PATCH 09/11] ready to merge? --- 06week/higherOrder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index df578a633..3dd998302 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -4,13 +4,13 @@ const assert = require('assert'); function forEach(arr, callback) { // create an array with whatever you want in it - const arrProblemOne = ['Eric', 'Eric', 'Eric', 'I promise I am not vain. Seriously'] + const arrProblemOne = [1, 2, 3] //make a for loop that runs the number of items in the array amount of times. //make a variable that prints a phrase the amount of times defined by the for loop for (let i = 0; i < arrProblemOne.length; i++) { const printTheArrayLength = () => { - console.log('Over and over!'); + console.log(callback); } } } From 7c87999847065edb5276cdf4595eab2cd941221c Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 18:04:28 -0600 Subject: [PATCH 10/11] ready to merge? --- 06week/higherOrder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index 3dd998302..5b88a8de0 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -9,8 +9,7 @@ function forEach(arr, callback) { //make a for loop that runs the number of items in the array amount of times. //make a variable that prints a phrase the amount of times defined by the for loop for (let i = 0; i < arrProblemOne.length; i++) { - const printTheArrayLength = () => { - console.log(callback); + callback(); } } } From d13546ecadd3b0844c31f2c6c3dc193ea7de57e3 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Thu, 9 Nov 2017 18:06:57 -0600 Subject: [PATCH 11/11] ready to merge? --- 06week/higherOrder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index 5b88a8de0..db3fbe750 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -23,7 +23,7 @@ function map(arr, callback) { //print out the new array const doThis = (arr, callBackFunction) => { const newArr = []; - arr.forEach((i) => { + test.forEach((i) => { newArr.push(callBackFunction(i)); }); console.log(newArr);