diff --git a/README.md b/README.md index e69d9d0..fd215ce 100644 --- a/README.md +++ b/README.md @@ -4,27 +4,41 @@ # Austin Coding Academy -## JavaScript 211 Project: Pig Latin +## JavaScript 211 Project: MasterMind ### Today's Checklist -1. Fork and Clone [Pig Latin Repo](https://github.com/AustinCodingAcademy/JS211_PigLatinProject.git) +1. Fork and clone [MasterMind Repo](https://github.com/AustinCodingAcademy/JS211_MasterMind) 1. Ensure you have installed all dependencies/packages: `npm i` -1. Look at the Unit Test, see what is being called, passed as input arguments, and what the expected result are. +1. Look at the Unit Test, see what is being called, passed as input arguments, and what the expected results are. 1. Ensure you know how to run the unit test: * `npm test main.js` -1. Use a whiteboard to work out a solution to building the Pig Latin program -1. Translate the broad ideas to psuedo code -1. Convert the psuedo code to real JavaScript Code +1. Follow the Specs below +1. Use a whiteboard to work out a solution to building the MasterMind program +1. Translate the broad ideas to pseudo code +1. Convert the pseudo code to real JavaScript Code 1. Type into your text editor the JavaScript code you've come up with one step at a time 1. Work through your bugs. 1. Use `node main.js` to run the game 1. Achieve green checks for each of your unit tests. +### Spec(ification)s + +1. Create a new branch called "masterMind" +1. **Spec 0 - Define a test solution:** Helpful suggestion: while developing you can set a default solution for you to test against. At the top of `mastermind()`, simply set `const solution = 'abcd';` as a global variable. +1. **Spec 1 - Detect a correct solution:** In `mastermind()`, if the `guess` you passed in equals the `solution`, `return` `'You guessed it!';`. +1. **Spec 2 - Generate a hint:** `generateHint()` should take one argument, `guess`. +1. **Spec 2.1 - Split up the** `solution` **and** `guess`**:** In `generateHint()`, create variables `solutionArray` and `guessArray` that each split up passed in arguments, [`.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)ting on `''` (empty string). +1. **Spec 2.2 - Determine correct "letter-locations":** Create a variable `correctLetterLocations` and set it to `0`. This variable will record how many correct "letter-locations" were guessed. For instance, a guess of `aabc` against a solution of `deba` would yield one correct "letter-location" (`b`). In a `for` loop, iterate over the `solutionArray`, comparing each index of `solutionArray` against the same index of `guessArray`. If the item matches, increment `correctLetterLocations`, and set that index in `solutionArray` to `null`. +1. **Spec 2.3 - Determine correct "letters":** Now that we have `null`ed the already counted `correctLetterLocations`, we can see if the `guessArray` contains any `correctLetters` that were not in the correct location. Set a variable `correctLetters` equal to `0`, and in a `for` loop, again iterate over the `solutionArray`. Using [`.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf), determine if the item at the current index in `guessArray` appears inside of `solutionArray`. Save that index in a variable called `targetIndex`. Now, `if` `targetIndex` is greater than `-1`, increment `correctLetters` and set the item in `solutionArray` at that index equal to `null`. +1. **Spec 2.4 -** `return` **hint string:** Optionally, you can use the [`colors`](https://www.npmjs.com/package/colors) package, `return` a string that prints out the hints you generated, with `correctLetterLocations` being red, `correctLetters` being white, and separated by a hyphen. (NOTE: If you choose to use this color package, only `console.log` the result. If you `return` the result your program will fail the tests.) +1. **Spec 3 - Add guess and hint to the board:** Define a variable called `hint` that collects the returned value of `generateHint(guess)`. `.push` the `guess` and the `hint` (as a combined string) into the `board`. +1. **Spec 4 - End the game:** After 10 incorrect guesses, if the `board` `length` equals `10`, `return` `'You ran out of turns! The solution was '` and the `solution`. Otherwise, `return` `'Guess again.'`. + ### Hints 1. Run your unit tests first!! -1. Use [repl.it](https://www.repl.it) to write the solution code first. (its a faster environment vs using the `node main.js` command over and over again.) +1. Use [repl.it](https://www.repl.it) to write the solution code first. (it's a faster environment vs using the `node main.js` command over and over again.) 1. Read the comments in `main.js` 1. Use the [JS Docs at W3S](https://www.w3schools.com/jsref/jsref_split.asp) 1. Push yourself further. @@ -100,12 +114,12 @@ example `node 01week/rockPaperScissors.js` ### Running Tests -Tests are a great way to make sure you code works the way you planned it would, +Tests are a great way to make sure your code works the way you planned it would, and to make sure you don't break something in the future. We will be using them to test our understanding of the lesson. It's also our main way to assign grades for an assignment. -To run a the tests on a file run `npm test path/to/file.js`, etc. +To run the tests on a file run `npm test path/to/file.js`, etc. ### Running the Linter