← Back to challenges

Rectangle Series 1: Skeleton

JavaScriptHardclassesgeometry

Instructions

Write a class called Rectangle that represents a rectangular two-dimensional region. It should have the following constructor:

constructor(x, y, width, height)
  • Constructs a new rectangle whose top-left corner is specified by the given coordinates and with the given width and height.

It should have the following properties:

x

y

width

height

It should have the following methods:

toString()
  • Returns a string representation of this rectangle, as [x=1, y=2, width=3, height=4].
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Fix the Error: Flattening an Array