diff --git a/04week/mastermind.js b/04week/mastermind.js index 58171507f..dbb5a70cf 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -1,26 +1,32 @@ 'use strict'; +import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from "constants"; + +/* const assert = require('assert'); const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); - +*/ let board = []; -let solution = ''; +let solution = 'a'; let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; + function printBoard() { for (let i = 0; i < board.length; i++) { console.log(board[i]); } } + +console.log(solution) function generateSolution() { - for (let i = 0; i < 4; i++) { - const randomIndex = getRandomInt(0, letters.length); - solution += letters[randomIndex]; + let generateSolutionArray = []; + for (let i = 0; i > 4; i++) { + generateSolutionArray.push(letters[getRandomInt(0,6)]); } } @@ -28,15 +34,50 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; } -function generateHint() { - // your code here +function generateHint(solution, guess) { + //turns the passed in strings into arrays + let solutionArray = solution.split(''); + let guessArray = guess.split(''); + //tells which letter locations are correct + var correctLetterLocations = 0; + //goes through each solution letter + for(let i=0;i -1){ + correctLetters = correctLetters + 1; + solutionArray[i] = null; + } + } + return correctLetterLocations + correctLetters; } +var hint = generateHint(solution,guess); +board.push(hint); function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here -} + //solution = 'abcd'; // Comment this out to generate a random solution + if(guess == solution){ + return 'you guessed ot' + } else { + var hint = generateHint(solution,guess); + board.push(hint); + } +} + function getPrompt() { rl.question('guess: ', (guess) => { @@ -47,7 +88,7 @@ function getPrompt() { } // Tests - +/* if (typeof describe === 'function') { solution = 'abcd'; describe('#mastermind()', () => { @@ -75,3 +116,4 @@ if (typeof describe === 'function') { generateSolution(); getPrompt(); } +*/ \ No newline at end of file