Complete the code to declare a function named greet that returns a string.
function greet() : [1] { return "Hello!"; }
The function greet returns a string, so the return type should be string.
Complete the code to declare a class named Person with a constructor that takes a name parameter.
class Person { name: string; constructor([1]: string) { this.name = name; } }
The constructor parameter should be named name to match the property assignment this.name = name;.
Fix the error in the method declaration inside the class Calculator.
class Calculator { add(a: number, b: number) : [1] { return a + b; } }
The add method returns the sum of two numbers, so its return type should be number.
Fill both blanks to declare a class Animal with a method makeSound that returns a string.
class [1] { [2]() : string { return "Some sound"; } }
The class name is Animal and the method name is makeSound which returns a string.
Fill all three blanks to declare a class Rectangle with a constructor and a method area that returns the area as a number.
class [1] { width: number; height: number; constructor([2]: number, [3]: number) { this.width = width; this.height = height; } area() : number { return this.width * this.height; } }
The class is named Rectangle. The constructor parameters are width and height to match the properties.