Return Early Pattern for Functions could you please help!

Tell us what’s happening:

I am now stuck on this exercise because when i press hint, i am directed to a stub and i have no idea what to contribute to this stub since i am new to programming and i don’t understand the how to navigate the page that opens.

Your code so far


// Setup
function abTest(a, b) {
  // Only change code below this line
  console.log(a, b);
  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt (b), 2));
  console.log(a,b);
  
  
  // 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/72.0.3626.121 Safari/537.36.

What do you need to do?
You need to check if a or b are negative numbers, and if one of them is negative you need to return from the function
What’s the way to write a piece of code that is executed only under a certain condition?

In this exercise, i can not use if else statements.

What made you think you can’t use an if statement?

Basically you need to check if a or b are less than 0 i.e., negative. If so you should return the type undefined.

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