From 3e74d34c95c1875f3a2c9e0cb9266054cc886007 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Thu, 19 Oct 2017 20:39:24 -0500 Subject: [PATCH 1/5] comments n stuff --- 01week/rockPaperScissors.js | 60 ------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 01week/rockPaperScissors.js diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js deleted file mode 100644 index 2794ebb00..000000000 --- a/01week/rockPaperScissors.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const readline = require('readline'); -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -// Compare hand1 and hand2 inputs and spit out a result -// written inside a whole function using if statements -// rock beats scissors; paper beats rock; scissors beat paper -// put the bulk in argument to minimize lines using pipes and ampersands -function rockPaperScissors(hand1, hand2) { - if (hand1 === hand2){ - return 'Tie!'; - } else if ((hand1 === 'rock' && hand2 === 'scissors') || (hand1 === 'paper' && hand2 === 'rock') || (hand1 === 'scissors' && hand2 === 'paper')){ - return 'Hand 1 is the victor!'; - } else if ((hand2 === 'rock' && hand1 === 'scissors') || (hand2 === 'paper' && hand1 === 'rock') || (hand2 === 'scissors' && hand1 === 'paper')) { - return 'Hand 2 is the victor!'; - } else { - return 'Someone is trying to cheat!'; - } -} - -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('rock', 'scissors'), "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!"); - }); - }); -} else { - - getPrompt(); - -} From 8c7738f2b263b0c9759c2f57004b17a8b354c45d Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Thu, 19 Oct 2017 20:45:02 -0500 Subject: [PATCH 2/5] comments n stuff --- 03week/ticTacToe.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..dcf68b043 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -24,23 +24,33 @@ function printBoard() { } function horizontalWin() { - // Your code here + // Winning Combos + // 00 01 02 + // 10 11 12 + // 20 21 22 } function verticalWin() { - // Your code here + // Winning Combos + // 00 10 20 + // 01 11 21 + // 02 12 22 } function diagonalWin() { - // Your code here + // Winning Combos + // 00 11 22 + // 02 11 20 } function checkForWin() { - // Your code here + // Check for any diagonal / vert / horiz wins } function ticTacToe(row, column) { - // Your code here + // if(indexOf()) methods using on click + // else if + } function getPrompt() { @@ -68,7 +78,7 @@ if (typeof describe === 'function') { }); it('should alternate between players', () => { ticTacToe(0, 0); - assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); + assert.deepEqual(board, [ ['O', '', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); }); it('should check for vertical wins', () => { board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', 'X', ' '] ]; From 08a80104c7c5b8a9d6033f154c6ddda77c610292 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 24 Oct 2017 14:24:37 -0500 Subject: [PATCH 3/5] trying to finish --- 03week/ticTacToe.js | 66 ++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index dcf68b043..fa3030f9f 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -23,36 +23,66 @@ function printBoard() { console.log('2 ' + board[2].join(' | ')); } -function horizontalWin() { - // Winning Combos - // 00 01 02 - // 10 11 12 - // 20 21 22 +const horizontalWin = () => { + if ((board[0][0] === board[0][1] && board[0][1] === board[0][2]) || (board[1][0] === board[1][1] && board[1][1] === board[1][2]) || (board[2][0] === board[2][1] && + board[2][1] === board[2][2])) { + return true; + } } -function verticalWin() { - // Winning Combos - // 00 10 20 - // 01 11 21 - // 02 12 22 +/* Run an conditional statement to make columns all equal to the same string +In columns "0", "1", "2" make variable 'block' for function verticalWin equal: +Column "0" =>[0,0], [1,0], [2,0] and Column "1" => [0,1], [1,1], ]2,0} +Column "2" =>[0,2], [1,2],[2,2]. */ +const verticalWin = () => { + if ((board[0][0] === board[1][0] && board[1][0] === board[2][0]) || (board[0][1] === board[1][1] && board[1][1] === board[2][1]) || (board[0][2] === board[1][2] && + board[1][2] === board[2][2])) { + return true; + } } -function diagonalWin() { - // Winning Combos - // 00 11 22 - // 02 11 20 +/* Run an conditional statement to make equal to the same string + make variable 'block' for function diagonalWin equal:[0,0], [1,1], [2,2] and + => [0,2], [1,1], ]2,0}. */ +const diagonalWin = () => { + if (board[0][0] === board[1][1] && board[1][1] === board[2][2] || (board[0][2] === board[1][1] && board[1][1] === board[2][0])) { + return true; + } } -function checkForWin() { - // Check for any diagonal / vert / horiz wins + +const checkForWin = () => { + if (horizontalWin() || verticalWin() || diagonalWin()) { + console.log(`Player ${playerTurn} Wins!`); + } else if (turnCount === 9) { + console.log("It's a tie!") + } else { + return false; + } + } function ticTacToe(row, column) { - // if(indexOf()) methods using on click - // else if + if (playerTurn === 'X') { + playerTurn = 'O'; + } else { + playerTurn = 'X'; + } + if (board[row][column] === ' ') { + board[row].splice(column, 1, playerTurn); + } + return false; + // } else { + // console.log(`The winner is player ${playerTurn}. Start a new game`); + // return true; + // } else { + // console.log('Please choose another block! That one is taken!'); + // } else { + // console.log('Please enter a valid index. Valid values are 0, 1, 2'); } + function getPrompt() { printBoard(); console.log("It's Player " + playerTurn + "'s turn."); From 0cc1698024299410a6079a8a8ecc1efcc7e89cd8 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 24 Oct 2017 17:05:19 -0500 Subject: [PATCH 4/5] moar stuff --- 03week/ticTacToe.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index fa3030f9f..786c2c484 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -30,10 +30,7 @@ const horizontalWin = () => { } } -/* Run an conditional statement to make columns all equal to the same string -In columns "0", "1", "2" make variable 'block' for function verticalWin equal: -Column "0" =>[0,0], [1,0], [2,0] and Column "1" => [0,1], [1,1], ]2,0} -Column "2" =>[0,2], [1,2],[2,2]. */ + const verticalWin = () => { if ((board[0][0] === board[1][0] && board[1][0] === board[2][0]) || (board[0][1] === board[1][1] && board[1][1] === board[2][1]) || (board[0][2] === board[1][2] && board[1][2] === board[2][2])) { @@ -83,6 +80,7 @@ function ticTacToe(row, column) { } + function getPrompt() { printBoard(); console.log("It's Player " + playerTurn + "'s turn."); From 3fbcbc48c15bd6ff2c688288580ed1f50da0a0f0 Mon Sep 17 00:00:00 2001 From: cfissell50 Date: Tue, 24 Oct 2017 17:24:38 -0500 Subject: [PATCH 5/5] as far as i can get right now --- 03week/ticTacToe.js | 58 +++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 786c2c484..120718df7 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -23,6 +23,10 @@ function printBoard() { console.log('2 ' + board[2].join(' | ')); } +// Check for winning horizontal with if +// 00 01 02 +// 10 11 12 +// 20 21 22 const horizontalWin = () => { if ((board[0][0] === board[0][1] && board[0][1] === board[0][2]) || (board[1][0] === board[1][1] && board[1][1] === board[1][2]) || (board[2][0] === board[2][1] && board[2][1] === board[2][2])) { @@ -30,7 +34,10 @@ const horizontalWin = () => { } } - +//Check for winning vertical with if +//00 10 20 +//01 11 21 +//02 12 22 const verticalWin = () => { if ((board[0][0] === board[1][0] && board[1][0] === board[2][0]) || (board[0][1] === board[1][1] && board[1][1] === board[2][1]) || (board[0][2] === board[1][2] && board[1][2] === board[2][2])) { @@ -38,45 +45,40 @@ const verticalWin = () => { } } -/* Run an conditional statement to make equal to the same string - make variable 'block' for function diagonalWin equal:[0,0], [1,1], [2,2] and - => [0,2], [1,1], ]2,0}. */ +// Check for winning diagonalWin with if +// 00 11 22 +// 02 11 20 const diagonalWin = () => { if (board[0][0] === board[1][1] && board[1][1] === board[2][2] || (board[0][2] === board[1][1] && board[1][1] === board[2][0])) { return true; } } - +// Got help from eddy, I do not completely understand yet const checkForWin = () => { - if (horizontalWin() || verticalWin() || diagonalWin()) { - console.log(`Player ${playerTurn} Wins!`); - } else if (turnCount === 9) { - console.log("It's a tie!") - } else { - return false; - } + // if (horizontalWin() || verticalWin() || diagonalWin()) { + // console.log(`Player ${playerTurn} Wins!`); + // } else if (turnCount === 9) { + // console.log("It's a tie!") + // } else { + // return false; + //} } +// Got help from eddy, I do not completely understand yet function ticTacToe(row, column) { - - if (playerTurn === 'X') { - playerTurn = 'O'; - } else { - playerTurn = 'X'; - } - if (board[row][column] === ' ') { - board[row].splice(column, 1, playerTurn); - } - return false; - // } else { - // console.log(`The winner is player ${playerTurn}. Start a new game`); - // return true; + // + // if (playerTurn === 'X') { + // playerTurn = 'O'; // } else { - // console.log('Please choose another block! That one is taken!'); - // } else { - // console.log('Please enter a valid index. Valid values are 0, 1, 2'); + // playerTurn = 'X'; + // } + // if (board[row][column] === ' ') { + // board[row].splice(column, 1, playerTurn); + // } + // return false; + }