Return Early Pattern for Functions- it keeps saying maximum call size exceeded, how can i do this correctly?

Tell us what’s happening:

Your code so far

// Setup
function abTest(a, b) {
  // Only change code below this line
  abTest(a < 0 || b < 0)
  return undefined;

  // 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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36.

Link to the challenge:

It seems that you are calling the function from within itself. This is just creating an infinite loop.

What the challenge is asking is for you to exit the function, before the given return statement is executed, if a or b are less than 0.

In order to do that you need an if statement which checks that condition and then simply returns if it is met.


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

This code is simply saying: if a is less than 0, or b is less than 0, return (exit the function).

thank you! how you explained it makes more sense

No problem at all. Glad to have helped you.