Create an IIFE that calculates area of rectangle
javascript
Instructions:
Create an IIFE that takes in the length and width of a rectangle and outputs the area to the console.
Expected result:
minMax([2, 9, 5, 3, 8, 0]);
// Min: 0 and Max: 9
Solution:
(function (length, width) {
const area = length * width;
console.log(
`Area of rectangle with length of ${length} and width of ${width} is : ${area}`
);
})(5, 6);
// Area of rectangle with length of 5 and width of 6 is : 30
Short version of above solution :
(function (length, width) {
console.log(
`Area of rectangle with length of ${length} and width of ${width} is : ${
length * width
}`
);
})(5, 6);
// Area of rectangle with length of 5 and width of 6 is : 30
Using arrow function:
((length, width) =>
console.log(
`Area of rectangle with length of ${length} and width of ${width} is : ${
length * width
}`
))(5, 6);
// Area of rectangle with length of 5 and width of 6 is : 30