• 4 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 2/7/20

Get some practice creating a candy counter

It's your turn

Remember the bowling example from the course? You're going to integrate a similar system using test driven development - except this time with candy!

Imagine that you're coding the inventory of a candy store, one of those awesome stores where you can load up a plastic bag with as much candy as you want. You want to keep track of the fact that when someone removes a bunch of candies from a bin in order to buy them, the stock of that candy decreases.

You also want to consider that when an employee reloads a certain candy bin, the stock of that candy increases. Writing code for these scenarios will help the store confirm it always has enough stock of each candy type.

The store offers:

  • Gummy bears

  • Reese's Pieces

  • Caramels

  • Skittles

  • Runts

  • Gumballs

  • Jelly beans

  • Lollipops

Choose 2 of the above candies and write simple tests that confirm:

  • When someone removes 20 candies from a bin of 510 candies (of one candy type), there should be 490 of the candy type left in the bin.

  • When an employee adds 600 candies to a bin that has 4 candies in it (of the second candy type), there should be 604 candies in that bin.

  • Removing candies of one type does not change the quantity of the other candy type.

Next, you'll write the accompanying JavaScript code that makes these tests pass one by one.

Check your work!

Check that the following elements are present:

  • Code passes test cases listed on the assignment:

    • "When someone removes 20 candies from a bin of 510 candies (of one candy type), there should be 490 of the candy type left in the bin.

    • When an employee adds 600 candies to a bin that has 4 candies in it (of the second candy type), there should be 604 candies in that bin.
      Removing candies of one type does not change the quantity of the other candy type."

  • Javascript test code is clean and readable using proper naming and capitalization conventions, like camelcase for variables

Example of certificate of achievement
Example of certificate of achievement