The area of rectangle is: w*h
The perimeter of rectangle is: 2 * (w + h)
The js code is:
function areaRectangle(a, b) {
console.log(a * b);//The area of rectangle is: w*h
console.log(2 * (a + b));//The perimeter of rectangle is: 2 * (w + h)
}
areaRectangle(2.5, 3.14);
The multiplication operator will automatically coerce the input variables to numbers, so we can directly find the area of the rectangle by multiplying the two input elements.
The remaining operations are straightforward arithmetic and finally printing the two results (area and perimeter) to the console.