Return Early Pattern for Functions 2

Return Early Pattern for Functions 2
0

#1

Tell us what’s happening:

Your code so far


// Setup
function abTest(a, b) {
  // Only change code below this line
  return a > 0;
  return b > 0;
  }
  
  // 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/69.0.3497.100 Safari/537.36.

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


#2

The problem with your code is a couple things.

First, it says to return undefined if a or b are LESS than 0, not greater. Your logic works fine, but a > 0 returns true or false and will never return undefined.

Instead, you may consider doing an if statement that checks a and b and returns undefined if either is less than 0


#3

Hey there.

In case you need a quick answer for any future challenges, you can search through the forum search topic and you will see that this topic was discussed and answered earlier too.

And as what @JordanMarsh mentioned above, you should use less than operator instead of greater than operator, use if statement and use logical OR statement. And use return statement with undefined as the keyword.

Good Luck.