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(); - -} diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..120718df7 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -23,26 +23,66 @@ function printBoard() { console.log('2 ' + board[2].join(' | ')); } -function horizontalWin() { - // Your code here +// 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])) { + return true; + } } -function verticalWin() { - // Your code here +//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])) { + return true; + } } -function diagonalWin() { - // Your code here +// 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; + } } -function checkForWin() { - // Your code here +// 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; + //} + } +// Got help from eddy, I do not completely understand yet function ticTacToe(row, column) { - // Your code here + // + // if (playerTurn === 'X') { + // playerTurn = 'O'; + // } else { + // playerTurn = 'X'; + // } + // if (board[row][column] === ' ') { + // board[row].splice(column, 1, playerTurn); + // } + // return false; + } + + function getPrompt() { printBoard(); console.log("It's Player " + playerTurn + "'s turn."); @@ -68,7 +108,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', ' '] ];