From 9b066457e7cd2650fefc8d5c45a64c9cd3d39366 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 24 Oct 2017 18:54:01 -0500 Subject: [PATCH 01/19] 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/19] 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/19] 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/19] 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 9dffa7be1a2d5b452c1259dc3ea36887c95266cc Mon Sep 17 00:00:00 2001 From: walzer85 Date: Mon, 30 Oct 2017 06:35:02 -0500 Subject: [PATCH 05/19] working on checkforwin --- 03week/towersOfHanoi.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 40b9ebe92..e2695b7af 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -20,17 +20,22 @@ function printStacks() { } function movePiece() { - // Your code here - -} - -function isLegal() { - // Your code here - + endStack.push(startstack.lastindexof) + startstack.lastindexof.slice + } + +const isLegal=()=> { + if(startstack.lastindexof > endStack.lastindexof) { + movePiece + } else { + return 'Not a legal move.'; + } } function checkForWin() { - // Your code here + if (stacks === [a: [], b: [1], c:[4, 3, 2, 1]]) { + return + } } @@ -50,5 +55,3 @@ function getPrompt() { } getPrompt(); - - From 4cab1556581a1ba0df0f959528bb25f9eabd6745 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Mon, 30 Oct 2017 07:13:11 -0500 Subject: [PATCH 06/19] need to start testing --- 03week/towersOfHanoi.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index e2695b7af..9d036bcca 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -19,12 +19,12 @@ function printStacks() { console.log("c: " + stacks.c); } -function movePiece() { +function movePiece(startstack, endStack) { endStack.push(startstack.lastindexof) startstack.lastindexof.slice } -const isLegal=()=> { +const isLegal=(startstack, endStack)=> { if(startstack.lastindexof > endStack.lastindexof) { movePiece } else { @@ -34,14 +34,13 @@ const isLegal=()=> { function checkForWin() { if (stacks === [a: [], b: [1], c:[4, 3, 2, 1]]) { - return - } + return "You win! Let's play again!"; + } else } function towersOfHanoi(startStack, endStack) { - // Your code here - + moviePiece } function getPrompt() { From 5ff6866abef67d9047f07de5775b8cb08b58d9d8 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Mon, 30 Oct 2017 21:16:38 -0500 Subject: [PATCH 07/19] adding function to reset the board --- 03week/towersOfHanoi.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 9d036bcca..4bec4df0d 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -7,40 +7,53 @@ const rl = readline.createInterface({ output: process.stdout }); +//This is the initial setting at the beginning of towersOfHanoi. Part of premade code let stacks = { a: [4, 3, 2, 1], b: [], c: [] }; -function printStacks() { +//This function prints the stacks on to the screen. Part of premade code +let printStacks() { console.log("a: " + stacks.a); console.log("b: " + stacks.b); console.log("c: " + stacks.c); } -function movePiece(startstack, endStack) { +//printBeginningStacks, reset the var stacks to its original position, nest stacks inside +const printBeginningStacks=(stacks)=> {} + let stacks = { + a: [4, 3, 2, 1], + b: [], + c: [] + }; +//movePiece(), Moves the last index of the startStack to the last index of the endStack, lastindexof method +const movePiece=(startstack, endStack)=> { endStack.push(startstack.lastindexof) startstack.lastindexof.slice } +//isLegal(), checks to see if the last index of the start stack is less than the end stack last index. If the value is less, run movePiece. If the value is greater, deny the move, lastindexof method const isLegal=(startstack, endStack)=> { - if(startstack.lastindexof > endStack.lastindexof) { + if((startstack.lastindexof < endStack.lastindexof) || (startstack.lastindexof > 0)) { movePiece } else { return 'Not a legal move.'; } } -function checkForWin() { +//checkForWin, +const checkForWin=()=> if (stacks === [a: [], b: [1], c:[4, 3, 2, 1]]) { return "You win! Let's play again!"; + } else } function towersOfHanoi(startStack, endStack) { - moviePiece + isLegal } function getPrompt() { From db7cadb4166ab346aaf9b156bab5e04ddc939a26 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Mon, 30 Oct 2017 21:35:12 -0500 Subject: [PATCH 08/19] doing last checks --- 03week/towersOfHanoi.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 4bec4df0d..4b67a2df5 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -43,15 +43,15 @@ const isLegal=(startstack, endStack)=> { } } -//checkForWin, +//checkForWin, if all of the numbers are in the last stack, run the win sequence, which should reset the object, if statement const checkForWin=()=> if (stacks === [a: [], b: [1], c:[4, 3, 2, 1]]) { - return "You win! Let's play again!"; - - } else - + console.log("You win! Let's play again!"); + printBeginningStacks; + getPrompt; + } } - +towersOfHanoi, only needs to reference the isLegal function to get the function towersOfHanoi(startStack, endStack) { isLegal } From 334606de0920c72232c3d9392f2468e5b1766c0f Mon Sep 17 00:00:00 2001 From: walzer85 Date: Mon, 30 Oct 2017 21:46:11 -0500 Subject: [PATCH 09/19] doing last checks --- 03week/towersOfHanoi.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 4b67a2df5..8eb918a4c 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -51,7 +51,8 @@ const checkForWin=()=> getPrompt; } } -towersOfHanoi, only needs to reference the isLegal function to get the + +//towersOfHanoi, only needs to reference the isLegal function to get the list of finctions running function towersOfHanoi(startStack, endStack) { isLegal } From d2483ca263ed94cb21ee183a3ba55684c744c023 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Tue, 31 Oct 2017 06:34:58 -0500 Subject: [PATCH 10/19] getting unexpected token errors for lines of code that don't exist --- package-lock.json | 13 +++++++++++++ package.json | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 62353c45d..740d43433 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3223,6 +3223,19 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/node/-/node-8.3.0.tgz", + "integrity": "sha512-RU3iQgXeDBU45dv6BrfDrgTyUjJk1yorN64l0sce+E+2pZzFbRbBicPMBD/hWjo0GSMnA5a+RwFtWwHNDlojaw==", + "requires": { + "node-bin-setup": "1.0.6" + } + }, + "node-bin-setup": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.0.6.tgz", + "integrity": "sha512-uPIxXNis1CRbv1DwqAxkgBk5NFV3s7cMN/Gf556jSw6jBvV7ca4F9lRL/8cALcZecRibeqU+5dFYqFFmzv5a0Q==" + }, "node-status-codes": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz", diff --git a/package.json b/package.json index 5c6742f79..df5b703ab 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "functional-javascript-workshop": "^1.0.6", - "javascripting": "^2.6.1" + "javascripting": "^2.6.1", + "node": "^8.3.0" } } From 1e0c4c9f8e28ba0d05c93e9fb4cd5a605f7ee294 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 06:22:30 -0600 Subject: [PATCH 11/19] reworking towers of hanoi assignment --- 03week/towersOfHanoi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 8eb918a4c..5753383db 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -28,10 +28,10 @@ const printBeginningStacks=(stacks)=> {} b: [], c: [] }; + //movePiece(), Moves the last index of the startStack to the last index of the endStack, lastindexof method const movePiece=(startstack, endStack)=> { endStack.push(startstack.lastindexof) - startstack.lastindexof.slice } //isLegal(), checks to see if the last index of the start stack is less than the end stack last index. If the value is less, run movePiece. If the value is greater, deny the move, lastindexof method From 9ebee871859046811d1d24aeae5234b9f24740ad Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:16:36 -0600 Subject: [PATCH 12/19] about to test isLegal --- 03week/towersOfHanoi.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 5753383db..0c8d4fae9 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -30,16 +30,22 @@ const printBeginningStacks=(stacks)=> {} }; //movePiece(), Moves the last index of the startStack to the last index of the endStack, lastindexof method -const movePiece=(startstack, endStack)=> { +const movePiece=(startStack, endStack)=> { endStack.push(startstack.lastindexof) } -//isLegal(), checks to see if the last index of the start stack is less than the end stack last index. If the value is less, run movePiece. If the value is greater, deny the move, lastindexof method -const isLegal=(startstack, endStack)=> { - if((startstack.lastindexof < endStack.lastindexof) || (startstack.lastindexof > 0)) { - movePiece - } else { +//isLegal(), checks to see if anything is in the first stack you choose. It then checks if the ending stack is empty. It then checks if the starting stack is smaller than the ending stack. If it meets all of those the move is legal +const isLegal = (startStack, endStack) => { + if (stacks[startStack].length === 0) { + console.log ('Please choose a stack with items in it! This move isn\'t legal!') + return false; + } else if( stacks[endStack].length === 0) { + return true; + } else if ((stacks[startStack].length - 1) > (stacks[endStack].length - 1)){ return 'Not a legal move.'; + return false; + } else { + return true; } } From a60e9af80e7de3b5ae7b7755a30ce6b99ee1f38e Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:38:27 -0600 Subject: [PATCH 13/19] fixed checkforwin --- 03week/towersOfHanoi.js | 13 +++++++------ package-lock.json | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 0c8d4fae9..2fc7684cc 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -8,14 +8,14 @@ const rl = readline.createInterface({ }); //This is the initial setting at the beginning of towersOfHanoi. Part of premade code -let stacks = { +let Stacks = { a: [4, 3, 2, 1], b: [], c: [] }; //This function prints the stacks on to the screen. Part of premade code -let printStacks() { +let printStacks = () => { console.log("a: " + stacks.a); console.log("b: " + stacks.b); console.log("c: " + stacks.c); @@ -50,11 +50,12 @@ const isLegal = (startStack, endStack) => { } //checkForWin, if all of the numbers are in the last stack, run the win sequence, which should reset the object, if statement -const checkForWin=()=> - if (stacks === [a: [], b: [1], c:[4, 3, 2, 1]]) { +const checkForWin = () => { + if (stacks[c].length === 3) { console.log("You win! Let's play again!"); - printBeginningStacks; - getPrompt; + } else { + console.log('Keep trying, you\'ll get there!') + return false; } } diff --git a/package-lock.json b/package-lock.json index 740d43433..c6f9c9cc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3224,9 +3224,9 @@ "dev": true }, "node": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/node/-/node-8.3.0.tgz", - "integrity": "sha512-RU3iQgXeDBU45dv6BrfDrgTyUjJk1yorN64l0sce+E+2pZzFbRbBicPMBD/hWjo0GSMnA5a+RwFtWwHNDlojaw==", + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/node/-/node-8.9.1.tgz", + "integrity": "sha512-Q+s+uYK6iNdsL91cHOPo1baugkdF6/m5zUbil4Ya9mMyfBnAn/J+htT5GniLIEsYRJ+mtBAWNR7XkePStXKFZQ==", "requires": { "node-bin-setup": "1.0.6" } diff --git a/package.json b/package.json index df5b703ab..882713b6f 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,6 @@ "dependencies": { "functional-javascript-workshop": "^1.0.6", "javascripting": "^2.6.1", - "node": "^8.3.0" + "node": "^8.9.1" } } From b0ec72363b4df154273a53dd28a5d587ab816699 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:42:38 -0600 Subject: [PATCH 14/19] fixed running the game --- 03week/towersOfHanoi.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 2fc7684cc..79eb6ea9f 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -60,8 +60,11 @@ const checkForWin = () => { } //towersOfHanoi, only needs to reference the isLegal function to get the list of finctions running -function towersOfHanoi(startStack, endStack) { - isLegal +const towersOfHanoi = (startStack, endStack) => { + if (isLegal(startStack, endStack) { + movePiece(startStack, endStack); + checkForWin(); + } } function getPrompt() { From 2036acf625a7dcc725f23030919d1bba39bdfb10 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:42:49 -0600 Subject: [PATCH 15/19] fixed running the game --- 03week/towersOfHanoi.js | 1 + 1 file changed, 1 insertion(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 79eb6ea9f..5640004e4 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -60,6 +60,7 @@ const checkForWin = () => { } //towersOfHanoi, only needs to reference the isLegal function to get the list of finctions running +//if the move is legal, move the piece then check if you've won const towersOfHanoi = (startStack, endStack) => { if (isLegal(startStack, endStack) { movePiece(startStack, endStack); From 4bcf051af0e35cdda83b092617eaa76ef74e57c6 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:47:18 -0600 Subject: [PATCH 16/19] checkforwin not working --- 03week/towersOfHanoi.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 5640004e4..1c2beac8e 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -29,10 +29,10 @@ const printBeginningStacks=(stacks)=> {} c: [] }; -//movePiece(), Moves the last index of the startStack to the last index of the endStack, lastindexof method +//movePiece(), Moves the last index of the startStack to the last index of the endStack, using pop and push const movePiece=(startStack, endStack)=> { - endStack.push(startstack.lastindexof) - } + stacks[endStack].push(stacks[startStack].pop()); +} //isLegal(), checks to see if anything is in the first stack you choose. It then checks if the ending stack is empty. It then checks if the starting stack is smaller than the ending stack. If it meets all of those the move is legal const isLegal = (startStack, endStack) => { @@ -62,7 +62,7 @@ const checkForWin = () => { //towersOfHanoi, only needs to reference the isLegal function to get the list of finctions running //if the move is legal, move the piece then check if you've won const towersOfHanoi = (startStack, endStack) => { - if (isLegal(startStack, endStack) { + if (isLegal(startStack, endStack)) { movePiece(startStack, endStack); checkForWin(); } From 89f4cbbfa97d10f86d89ccbc2c113af4f9a5ec4a Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 14:51:44 -0600 Subject: [PATCH 17/19] fixed check for win, needed to change from [] to . --- 03week/towersOfHanoi.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 1c2beac8e..d8e2e78ce 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -30,6 +30,7 @@ const printBeginningStacks=(stacks)=> {} }; //movePiece(), Moves the last index of the startStack to the last index of the endStack, using pop and push +//using push, add the last value in your starting stack (using pop) to the end of your ending stack const movePiece=(startStack, endStack)=> { stacks[endStack].push(stacks[startStack].pop()); } @@ -51,7 +52,7 @@ const isLegal = (startStack, endStack) => { //checkForWin, if all of the numbers are in the last stack, run the win sequence, which should reset the object, if statement const checkForWin = () => { - if (stacks[c].length === 3) { + if (stacks.c.length === 3) { console.log("You win! Let's play again!"); } else { console.log('Keep trying, you\'ll get there!') From 7a7fb41d7cd406ba2ac6e6c5650594ee50a4c828 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 15:05:56 -0600 Subject: [PATCH 18/19] fixed length for checkForWin --- 03week/towersOfHanoi.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index d8e2e78ce..f4f77da1d 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -8,7 +8,7 @@ const rl = readline.createInterface({ }); //This is the initial setting at the beginning of towersOfHanoi. Part of premade code -let Stacks = { +let stacks = { a: [4, 3, 2, 1], b: [], c: [] @@ -22,12 +22,14 @@ let printStacks = () => { } //printBeginningStacks, reset the var stacks to its original position, nest stacks inside -const printBeginningStacks=(stacks)=> {} - let stacks = { +const printBeginningStacks = (stacks) => { + stacks = { a: [4, 3, 2, 1], b: [], c: [] - }; + } + console.log('I want to play again, so we will.') +} //movePiece(), Moves the last index of the startStack to the last index of the endStack, using pop and push //using push, add the last value in your starting stack (using pop) to the end of your ending stack @@ -52,7 +54,7 @@ const isLegal = (startStack, endStack) => { //checkForWin, if all of the numbers are in the last stack, run the win sequence, which should reset the object, if statement const checkForWin = () => { - if (stacks.c.length === 3) { + if (stacks.c.length === 4) { console.log("You win! Let's play again!"); } else { console.log('Keep trying, you\'ll get there!') From dc9770ab88f58d515b1d253d2a6aa3289ef46737 Mon Sep 17 00:00:00 2001 From: walzer85 Date: Sat, 2 Dec 2017 15:10:37 -0600 Subject: [PATCH 19/19] I think I'm ready for regrading, still working to get board to reset, but in a much better place than before --- 03week/towersOfHanoi.js | 1 + 1 file changed, 1 insertion(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index f4f77da1d..ccfb90361 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -56,6 +56,7 @@ const isLegal = (startStack, endStack) => { const checkForWin = () => { if (stacks.c.length === 4) { console.log("You win! Let's play again!"); + printBeginningStacks(stacks); } else { console.log('Keep trying, you\'ll get there!') return false;