From 50dec7629d36c0fe80c93f9816f6f60340fc2753 Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Sat, 20 Jun 2020 16:46:57 -0500 Subject: [PATCH 1/2] updates --- 04week/mastermind.js | 9 +++++++-- JS211_ArrayPractice | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) create mode 160000 JS211_ArrayPractice diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..29f284725 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -21,6 +21,7 @@ function generateSolution() { for (let i = 0; i < 4; i++) { const randomIndex = getRandomInt(0, letters.length); solution += letters[randomIndex]; + } } @@ -28,12 +29,16 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; } -function generateHint() { +function generateHint(guess) { // your code here + let solutionArray = []; + let guessArray = []; + + } function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution + //solution = 'abcd'; // Comment this out to generate a random solution // your code here } diff --git a/JS211_ArrayPractice b/JS211_ArrayPractice new file mode 160000 index 000000000..1e00855c6 --- /dev/null +++ b/JS211_ArrayPractice @@ -0,0 +1 @@ +Subproject commit 1e00855c6576c929c7efa4a62225a720d36dd08a From 0acf95b31ea50e3b3c916cae0018e8f3dfa1a54b Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Tue, 23 Jun 2020 19:02:13 -0500 Subject: [PATCH 2/2] changes --- 04week/mastermind.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 29f284725..fdb5b8363 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -31,15 +31,51 @@ function getRandomInt(min, max) { function generateHint(guess) { // your code here - let solutionArray = []; - let guessArray = []; + let solutionArray = solution.split(""); + let guessArray = guess.split(""); + let correctLetterLocation = 0; + let correctLetters = 0; + + for(let i = 0; i < 4; i++){ + if(solutionArray === guessArray){ + correctLetterLocation++; + solutionArray = null; + } + } + console.log(solutionArray); + console.log(guessArray); + + for(let i = 0; i < 4; i++){ + let targetIndex = solutionArray.indexOf(guessArray[i]); + if(targetIndex < -1) { + correctLetters++; + solutionArray[targetIndex] = null; + console.log(solutionArray); + } + } + + return correctLetterLocation + "-"+ correctLetters; + +} +function checkForWin(guess, solution){ + if(guess === solution){ + return true; + } else{ + return; + } } function mastermind(guess) { //solution = 'abcd'; // Comment this out to generate a random solution // your code here + let hint = generateHint(guess) + board.push(`Guess: ${guess} - Hint: ${hint}`); + if(checkForWin(guess, solution) == true){ + return "You Guessed it!"; + } + }