Return-early-pattern-for-functions

Tell us what’s happening:
please guide:
how to return an 'undefined 'as result from the function.

Your code so far



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

Your browser information:

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

Link to the challenge:

Just put return undefined; in the correct place.

try it … throwing an error
function abTest(a, b) {

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

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

Right now you are only returning undefined if either a or b is 0. The instructions are to return undefined if one of them is less than 0.

If i call the function abTest :

abTest(-3,3); then the instructions are true right.
will this work ?

abTest(-3,3) should return undefined.

it is throwing an error to me.

check in the freecode forum link above once.

That isn’t one of the test cases. I told you why you’re failing some of the tests though.

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

In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

// Setup
function abTest(a, b) {
// Only change code below this line
if (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
abTest(2,2);
console.log(abTest(2,2));

This passes all the tests. As Ariel mentioned, read the directions because it asks to return undefined if one or the other is less than 0. Not sure why you are getting errors.

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

Got it Arielle thanks for the tip!

sorry its not working

If you’re having trouble with a challenge, you can create a forum thread with your code and a description of the problems that you’re having.