From abf6edb916a2c962a42eed77177a6d1122594804 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Tue, 30 Oct 2018 20:05:57 -0500 Subject: [PATCH 1/3] Main Function Orginisation --- 04week/mastermind.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..105e5140c 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -32,9 +32,39 @@ function generateHint() { // your code here } + +const isValid = (guess)=>{ + +} + +// user makes a guess +// start to match the guess against the solution +// guess has to be valid (letters, four of them, can't be empty) +// if not, tell why +// put guess on the board +// check for win +// if there is a win, tell user and reset board +// if there is not a win check for turns +// if user is on turn 10 show solution tell user and reset +// if user isn't show hunts +// how many letters are right place, right letters wong place function mastermind(guess) { solution = 'abcd'; // Comment this out to generate a random solution - // your code here + if(isValid(guess)){ + board.push(guess) + if(checkForWin()){ + console.log("You won"); + resestGame(); + }else{ + if(board.length<10){ + showHint(); + }else{ + console.log(solution); + console.log("You lost"); + resestGame(); + } + } + } } From 16c0255f906d5cd5cc3e9e2e13afad0c1f8b5f43 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Sun, 4 Nov 2018 11:00:51 -0600 Subject: [PATCH 2/3] I have no idea what change I made --- 04week/mastermind.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 105e5140c..82d3f2fdf 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -28,13 +28,36 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; } -function generateHint() { - // your code here -} +const showHints= (guess) =>{ + let matchPositionColor = 0; + let matchColor = 0; + const arraySolution = solution.split(""); + const arrayGuess = guess.split(""); + arrayGuess.forEach((letter,index )=> { + if(letter == arraySolution[index]){ + console.log(arrayGuess,arraySolution) + matchPositionColor++; + arraySolution[index]='!' + console.log(arrayGuess,arraySolution) + }else{ + if(arraySolution.indexOf(letter)!=-1){ + console.log(arrayGuess,arraySolution) + arraySolution[index]="!"; + matchColor++; + console.log(arrayGuess,arraySolution) + } + } + }); + return `Number of matched color and position ${matchPositionColor} number of matched just color ${matchColor}` +} const isValid = (guess)=>{ + return true; +} +const checkForWin = () =>{ + return false; } // user makes a guess @@ -57,7 +80,7 @@ function mastermind(guess) { resestGame(); }else{ if(board.length<10){ - showHint(); + console.log(showHints(guess)); }else{ console.log(solution); console.log("You lost"); From 6969a74e55c0e6431bd9f569b60a4c67e6de0592 Mon Sep 17 00:00:00 2001 From: Christopher Willis Date: Mon, 5 Nov 2018 19:58:07 -0600 Subject: [PATCH 3/3] meqggehgf --- 04week/mastermind.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 82d3f2fdf..a29e04216 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -42,7 +42,7 @@ const showHints= (guess) =>{ }else{ if(arraySolution.indexOf(letter)!=-1){ console.log(arrayGuess,arraySolution) - arraySolution[index]="!"; + arraySolution[arraySolution.indexOf(letter)]="!"; matchColor++; console.log(arrayGuess,arraySolution)