Write code to "safely" calculate the perimeter and area of a rectangle. The sides of a rectangle can only be a number (data type Number, values of other data types cannot be set), the value of which is strictly greater than 0. Code must be in Secure Closure format. Why doesn't validation work in my code that values are strictly greater than 0 and how to validate that there are only numbers
function createPOWandS() {
var x = 0;
var y = 0;
var arr = [];
arr[0] = function(newSum) {
if (newSum >= 0) {
x = newSum;
y = newSum;
}
};
arr[1] = function() {
return 2 * (x + y);
};
arr[2] = function() {
return x * y;
}
return arr;
}
var sqrt = createPOWandS();
sqrt[0](2, 2);
console.log(sqrt[1]());
sqrt[0](2, 2);
console.log(sqrt[2]());