In this **Day 4: Create a Rectangle Object 10 days of javascript** problem you need to complete the function in the editor. It has two parameters: a and b. It must return an object modeling a rectangle that has the following properties:

- the length that is equal to a.
- width: that is equal to b.
- perimeter: that is equal to 2*(a+b)
- area: that is equal to a*b

# HackerRank Day 4: Create a Rectangle Object 10 days of javascript problem solution.

'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.trim().split('\n').map(string => { return string.trim(); }); main(); }); function readLine() { return inputString[currentLine++]; } /* * Complete the Rectangle function */ function Rectangle(a, b) { this.length = a; this.width = b; this.area = a * b; this.perimeter = 2 * (a + b); } function main() { const a = +(readLine()); const b = +(readLine()); const rec = new Rectangle(a, b); console.log(rec.length); console.log(rec.width); console.log(rec.perimeter); console.log(rec.area); }

## 0 Comments