find the area of a rectangle in typescript

To find the area of a rectangle in TypeScript, we need to multiply the length and the width of the rectangle.

Here is the code to find the area of a rectangle in TypeScript:

index.ts
function findRectangleArea(length: number, width: number): number {
  const area: number = length * width;
  return area;
}

const length = 10;
const width = 5;
const area = findRectangleArea(length, width);

console.log(`Area of rectangle with length ${length} and width ${width} is ${area}`);
295 chars
11 lines

In the above code, we have defined a function called findRectangleArea that takes two arguments: length and width, both of type number. We then multiply the two values and store the result in a variable called area. Finally, we return the area.

In the main program, we have defined the length and width of the rectangle, and then we call the findRectangleArea function with these values. We store the returned value in a variable called area and then output the result using console.log.

The output of the above program will be:

index.ts
Area of rectangle with length 10 and width 5 is 50
51 chars
2 lines

gistlibby LogSnag