Typescript Classes 10 exercises

Creating Constructors for Classes in TypeScript

We're continuing to work with the CanvasNode class with default x and y positions and a move method:

class CanvasNode {
x = 0;
y = 0;
move(x: number, y: number) {
this.x = x;
this.y = y;

The test for movability is still in place, and we now have an ad

Loading exercise


00:00 In this exercise, our canvas node is still in place. We've still got X and Y as the defaults, and we've still got our first test that we had before should be able to move our canvas node. But we're now also expecting it to be able to receive an initial position. Our canvas node should be able to receive an optional initial position,

00:17 which basically sets the X and Y as the starting position here. Your job here is to try to find a way to get this working with the setup that we have already. So you should, you're probably gonna need a constructor, and you might need to have an argument in that constructor. Good luck.