Coder Social home page Coder Social logo

lab-create-your-own-js-class's Introduction

Lab: Create Your Own JavaScript Class

To practice OOP in JavaScript, we are going to be making a bank account class!

Getting started

  • fork and clone this repo to your local machine, then cd into the cloned directory
  • open index.html in your browser and use the browser's console to complete this lab
  • bank-class.js is already linked up to index.html and ready to use

Bank Account Class

You should use the class keyword to create a BankAccount class. Here are the implementaion details for your BankAccount class:

  • Bank accounts should be created with an accountType property (like "savings" or "checking").
  • Bank accounts should have a class-level (static) variable tracking the total amount of money in all accounts.
  • Each account should keep track of it's current balance.
  • Each account should have access to a deposit and a withdraw method.
    • The deposit method should add a specified amount to the account's balance.
    • The withdraw method should subtract a specified amount to the account's balance.
  • Each account should start with a balance set to zero.

Use the new keyword to create an instance of your bank account class and test it with console.log() in your browser as you work.

Things to think about

  • Any starting values for variables should be set in the constructor method
  • Static variables are declared using the static keyword inside the class but outside any methods
  • Instance variables are declared inside the constructor method
  • Does your constructor method need to accept any parameters?

Stretch Goals

  • Start each account with an additional overdraftFees property that starts at zero. If a call to withdraw ends with the balance below zero then overdraftFees should be incremented by twenty.
  • Create a ChildBankAccount class that overrides the withdraw method to eliminate the overdraft penalty fee and simply disallow the withdrawal if there aren't enough funds.

lab-create-your-own-js-class's People

Contributors

weston-bailey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.