Return Early Pattern for Functions - Help!

Tell us what’s happening:
How go i solve this one??

Your code so far


// Setup
function abTest(a, b) {
  // Only change code below this line
  function abTest(a,b=0){
    return undefined;
  }
function abTest(a,b=2){
 return 8;
}

if(a,b=-2,2){
  return undefined;
}
if(a,b=2,-2){
  return undefined;
}
if(a,b=2,8){
  return 18;
}
if(a,b=3,3){
  return 12;
}
  
  
  // 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);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions/

Wow. So… wow. So it should be, at most, three lines. The lesson is asking you to simply check if(...) the the value of a is less than zero, OR if the value of b is less than zero. If either is, return undefined.

So I’d say one line for the if (<something something){ line, one for the return statement, and one to close the } bracket.

Bear in mind that you can check for multiple values in your if(...), but not like that. Instead, try this:

if ( <first thing to check> || <second thing to check> ){
  return <something>
}

the || is a logical OR in javascript. That says “if the first condition is true, OR the second is true, do this block”. What do you think you need to put in for the first and second thing to check?

Don’t overthink this! :wink: