Read the question, write TypeScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Class Rectangle with width/height; method area(). Read w h; log area.
Input. Two numbers.
Output. Area.
Examples
Input
3 4
Output
12
Hint
- class Rectangle { constructor(w,h){...} area(){ return this.w*this.h } }
Show correct code
Peek only after you have tried. You can still Check your own version.
class Rectangle {
constructor(w, h) {
this.w = w;
this.h = h;
}
area() {
return this.w * this.h;
}
}
const [w, h] = readLine().trim().split(/\s+/).map(Number);
console.log(new Rectangle(w, h).area());
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.