Note: This can be a pair programming activity or done independently.
Take a look at the animation above. We're going to build that!
- Target and manipulate DOM elements
- Capture data from a submitted HTML form
- Update the DOM with new data
- Maintain the program's 'state' between interactions
Note: This exercise includes unit tests, so you'll be able to see instantly if your functions work properly by running tests, and passing them.
Read more: Test-Driven Development
- Fork this repo into your account.
- Once the forking is complete, clone the repo onto your computer.
cd
into the new folder.- From the command-line:
npm i
(this will get all the tools necessary for this exercise).git checkout -b solution
to start working on a new solution.
- Open js/app.js
- Each function and its behavior are described in each function's comments.
- Find all the
TODO: [xx]
comments; they'll describe what to do - All the function names are already inside the file; you just need to implement the function by adding code inside each one.
- Additionally, you can take a look at the full function documentation.
- For best results, have your terminal and your text-editor side-by-side on your screen. It'll help you keep an eye on your progress.
Run the following command in the Terminal (in this folder):
npm test
- (
ctrl-c
to quit) - The tests will initially fail (red).
- Correct functionality will cause the tests to pass (green).
When you've completed the lab,
- Commit it and push to Github Enterprise.
- Create a pull request with your solution.
- There is no submit button, so pressing
enter
in the input field will submit the form. - Keeping track of the total maintains the state of your application.
- Commit early, Commit often, git is your friend!
- Pseudocode! Plan out your project before you write a line of code.
- Draw pictures! Having a visual representation of your project to work from is super helpful!
- Keep your functions short and conscise. A function should only do one thing!
There's a bug in the code! When the user enters a non-numeric value into the field, NaN
is produced and the program ceases to function properly.
- Why is this happening?
- How can you validate so the user can only enter numeric data (and decimals)?
- Will your method work with all kinds of browsers?
What are these prices for? What did you buy? Let's add itemizations for each purchase!
- Each purchase should have a description on the left side of each price. (The extra
<td>
is already provided for you.)- Does the new description text need to be styled to fit so it aligns left?
- Make another input field so the user can input the purchase description.
- Which functions have to change to handle this new information?
- How does this new field fit into the current design?
- Get creative, but don't redesign it; just make it work in the current design.