Skip to main content
Version: v1.2

✏️ 4.1.2.1 Power Plant, Project Euler

Goal: Use closures to store state. Practice using composition to add functionality to objects. Focus on testing your applications thoroughly and keeping your business logic functional.

Warm Up


  • What is composition? How is it different from inheritance?
  • How can we make a shallow copy of an object in JavaScript?
  • What is the difference between a shallow copy and a deep copy?
  • How is it possible to store information inside a closure?

Code


Power Plant

Follow along with the homework to build an application for growing plants. Make sure to include tests, to separate your logic, and to use webpack. Once you have completed the example shown in the coursework, try adding the following functionality.

  • Add functionality to create multiple plants. Remember that we can use closures to store state about different objects.

  • Add functionality so different plants have different abilities. Use composition to add these abilities.

  • Build out a fully functioning game where users can feed their plants. This could include a UI, special powerups, and any creative functionality you might want to add!

Project Euler Problems

You've had a chance to solve Project Euler problems in Intermediate JavaScript. Now try coming up with functional solutions to some of these problems. Functional programming is often used for math and computation so this is a great way to get more practice with functional techniques.

Do not worry about implementing a UI. Focus on writing and testing functional code.

Instructor/Peer Code Review


  • Code correctly uses closures to store state when needed.
  • Code is well tested.
  • Objects are copied instead of mutated.
  • Application works as expected.