function calculateArea(length, width) {
if (length || width <= 0) {
return “Error: Length and width must be positive numbers.”;
}
return length * width;
}
console.log(calculateArea(-5, 10)); // What will this output?
function calculateArea(length, width) {
if (length || width <= 0) {
return “Error: Length and width must be positive numbers.”;
}
return length * width;
}
console.log(calculateArea(-5, 10)); // What will this output?
if (length || width <= 0)
Your conditional statement essentially checks, ‘if length exists or if width is smaller or equal to zero’.
You need to specify the condition explicitly for both length
and width
.