GithubHelp home page GithubHelp logo

fewpjs-class-extensions-extends-lab-chi01-seng-ft-080320's Introduction

JavaScript Class Extension Lab: extends

Learning Goals

  1. Practice writing JavaScript classes that inherit from other classes

Introduction

In this lab we're going to create a geometry application that allows us to calculate different properties of multiple shapes. We'll be using JavaScript's class keyword to build objects that inherit from its base object.

Practice Writing JavaScript classes That Inherit From Other Classes

  1. Define a Polygon class. Polygon will accept an Array of integers as a parameter, which will represent each side of a shape.
  • Use the get keyword to make a getter method countSides that counts the number of sides (each index in the array).
  • Use the get keyword to make a getter method perimeter that calculates the sum of each side (each index in the array) of the polygon. This method will become accessible to its child classes.
  1. Define a Triangle class that inherits from Polygon.
  • It will automatically have access to count and perimeter inherited from Polygon.
  • Use the get keyword to make a getter method isValid that checks if the given 3 sides for a triangle is valid.

The sum of the lengths of any two sides of a triangle is greater than the length of the third side. If you take the three sides of a triangle and add them in pairs, the sum is greater than (not equal to) the third side. If that is not true, then it is not possible to construct a triangle with the given side lengths.

  1. Define a Square class that inherits from Polygon.
  • It will automatically have access to count and perimeter inherited from Polygon.
  • Use the get keyword to make a getter method isValid that checks if the given 4 sides for a square is valid. A square is valid when the lengths of all sides are equal.
  • Use the get keyword to make a getter method area that calculates the area of the square.

Resources

fewpjs-class-extensions-extends-lab-chi01-seng-ft-080320's People

Contributors

drakeltheryuujin avatar maxwellbenton avatar codyjgreen avatar geluso avatar thuyanduong-flatiron avatar hwangjf avatar jenmyers avatar rrcobb avatar sylwiavargas avatar dependabot[bot] avatar

Watchers

James Cloos avatar Kaitlin Vignali avatar  avatar Victoria Thevenot avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar Ben Oren avatar Matt avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Vicki Aubin avatar  avatar  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.