# Return Early Pattern for Functions

this setup

// Setup
function abTest(a, b) {
// Only change code below this line

// Only change code above this line

return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(-2,2);
See i got see below wrong
abTest(-2,2) should return undefined
abTest(2,-2) should return undefined

we want to know more about the problem.

who are the requirements?

a minur observation is that sqrt function cannot contain negative values

// Setup
function abTest(a, b) {
// Only change code below this line

if(a<0 || b<0){
return;
}

// Only change code above this line

return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);

2 Likes

What @amazigh1989 said.

But just to add: Since apparently the test specifically asks for ‘undefined’ to be returned in those cases, it would be good practice to actually return that ‘undefined’ explicitly, i.e.:

``````if(a<0 || b<0){
return undefined;
}
``````

This helps readability of your code. People will know that you really do intend to return `undefined`.

4 Likes

Hi,

Isn’t if(a<0 || b<0){
equivalent to "if ((a || b ) <0 ) {
???

No. Look at the following example:

``````var a = 10;
var b = -1;

console.log(a < 0 || b < 0);
// above displays true because a<0 is false and b<0 is true, so true || false is true

console.log((a || b) < 0)
// displays false because (a || b) is 10  and  10 < 0 is false
`````` its makes sense this way