Code Monkey home page Code Monkey logo

ts_figures_classes's Introduction

Figures

We have 3 types of figures: triangles, circles and rectangles.

Write an interface Figure and 3 classes implementing it so that every figure has:

  • a shape (triangle, circle or rectangle);
  • a color (red, green or blue);
  • a method getArea that returns the area of the figure rounded down to hundredths.

In addition to a color constructors should accept required data:

  • sides a, b and c for a triangle;
  • a radius for a circle;
  • a width and a height for a rectangle.

The constructors should throw new Error('your error message') if:

  • any length is <= 0
  • the longest side of a triangle is >= than a sum of two others

Hints:

  • use Math.PI for calculating a circle square
  • use Heron's formula for triangles

Example:

new Rectangle('blue', 2, 0) // throws an error
new Triangle('red', 1, 2, 3) // throws an error: sides 1, 2 and 3 can't form a triangle

Also create a function getInfo that takes a figure and returns a string in the next format:

const redRectangle = new Rectangle('red', 3, 5);
getInfo(redRectangle) === 'A red rectangle - 15';

const greenCircle = new Circle('green', 1);
getInfo(greenCircle) === 'A green circle - 3.14';

ts_figures_classes's People

Contributors

oleksandra-pasenchenko avatar mgrinko avatar vinniej-2k20 avatar d-wasilewski avatar danheim 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.