Exercise Monday

Reminder: Node.js must be installed on your personal machine before Tuesday, as detailed in your weekend homework. If you encounter any issues in doing so, Epicodus staff will be available for assistance Tuesday at 10:30am.

Goal: Practice using npm and webpack to streamline your development process.

  • Separate logic into at least two JS files (business logic and interface logic). Use import and export statements to get them communicating.
  • Configure webpack to include all of the functionality covered in the weekend prework.
  • You are not expected to complete all of the options on this page. Start by following along with the weekend prework. Then proceed to the journal project. If you have additional time, pick either Memory or Simon.
  • Feel free to expand on these problems to challenge yourself if you want, but only after you have the basics working (including webpack fully set up, a fully functioning package.json file, and modularized code).

Warm Up


  • What is npm? Why would we want to use it?
  • What is webpack and what is it used for?
  • What is a dependency graph?
  • What is the difference between concatenation and minification?
  • What is linting? Why is it useful in development?

Code


Ping Pong

Follow along with the weekend homework to build a basic ping pong app that uses webpack and properly separates business and interface logic into separate files.

Journal

Create a journaling website where a user can write entries including at least a title and body. Create Entry objects that include a method to return the number of words in the entry. Then, add a separate method (or methods) to return the number of vowels and consonants in each entry. Call each of these methods from your front-end file to display their return values. Finally, add a method called getTeaser to return the first sentence of the entry. If the sentence is over 8 words, only display those first 8 words. Be sure to call this method from your front-end file to display the results as well, whenever a new journal entry is created.

Memory

Create a game based on the card game Memory.

You'll need to generate a grid of cards. Each card should have a picture on it, and there should be 2 of each picture. So, if you have a deck of 10 cards there should be 5 different pictures.

All cards should start face down. Each time the user takes a turn they click on 2 cards. When a card is clicked it should reveal its picture. If the user gets a pair of cards with the same picture, the cards remain face-up. If the user's selected cards are different they should return to face down. When all the cards are face up, the user has won. The object of the game is to find all the pairs in as few turns as possible.

Simon

Create a version of the old game Simon. In Simon, the game generates a sequence of colored lights for you to mirror. It starts out simple; first only one color, then if you get that right then you have to remember 2 colors. The sequence does not change every time, it just gets longer and longer.

For example, here is a sequence of turns:

["red"]
["red", "blue"]
["red", "blue", "yellow"]
["red", "blue", "yellow", "red"]
["red", "blue", "yellow", "red", "red"]
["red", "blue", "yellow", "red", "red", "yellow"]
...

You do not have to use the above format to generate sequences, this is just an example.

Hint: since this game involves timed events (we have to time how fast it takes for the sequence to play on each turn) you may wish to investigate the JavaScript function setInterval().

Peer Code Review


  • Does the app function and look well presented in the browser? Is the code clean and readable?
  • Is the project structured in a logical way, with functions kept in separate files from DOM manipulation code?
  • Does the project have an npm manifest file and .gitignore file?
  • Is webpack configured to minify, concatenate, browserify, lint, build and clean your code?