In this Day 1 Arithmetic Operators 10 days of javascript problem you need to Complete the getArea(length, width) function that Calculate and return the area of a rectangle having sides length and width. and a getPerimeter(length, width) function that Calculates and returns the perimeter of a rectangle having sides length and width.

HackerRank Day 1: Arithmetic Operators 10 days of javascript solution


HackerRank Day 1 Arithmetic Operators problem solution in JavaScript programming.

'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++];
}

/**
*   Calculate the area of a rectangle.
*
*   length: The length of the rectangle.
*   width: The width of the rectangle.
*   
*	Return a number denoting the rectangle's area.
**/
function getArea(length, width) {
    return length * width;
}
function getPerimeter(length, width) {
    return 2 * (length + width);
}


function main() {
    const length = +(readLine());
    const width = +(readLine());
    
    console.log(getArea(length, width));
    console.log(getPerimeter(length, width));
}