Question: create a new class called rectangle Rectangletests: // const myRectangle = new Rectangle(3, 5); // console.log(myRectangle.width === 3); // console.log(myRectangle.height === 5); // console.log(myRectangle.perimeter() ===
| create a new class called rectangle | ||||||||||||||
|
create a new class called Square
| // cheat sheet: a square is just a rectangle where the width and the height are the same! the tricky part here is building the right constructor. once that is done, the Rectangle class will do all the work. in other words, you should not have to define a new perimeter and area for the square. | |
| // Write your Square class here |
| Squaretests | |
| // const mySquare = new Square(2); | |
| // console.log(mySquare instanceof Rectangle === true); | |
| // console.log(mySquare.width === 2); | |
| // console.log(mySquare.height === 2); | |
| // console.log(mySquare.perimeter() === 8); | |
| // console.log(mySquare.area() === 4); |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
