Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Rectangle Area

Object-Oriented Programmingeasy

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 226: ES6 Classes

Define a `Rectangle` class with an `area()` method, and implement `rectangleArea(w, h)` that returns the area of a new rectangle.

Sample tests

Input: rectangleArea(3, 4)
Output: 12
Input: rectangleArea(5, 5)
Output: 25

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Forgetting new when instantiating the class.

Learning resources

  • MDN: Classes
Visualize this concept: ES6 Classes →
Approach & explanation (try first)

A class encapsulates the dimensions and exposes area() that multiplies them.

Loading...
⌘/Ctrl + Enter

Run your code to see results.