Return-early-pattern-for-functions

Return-early-pattern-for-functions
0.0 0

#1

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:


#2

Just put return undefined; in the correct place.


#3

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


#4

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.


#5

If i call the function abTest :

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


#6

abTest(-3,3) should return undefined.


#7

it is throwing an error to me.


#8

check in the freecode forum link above once.


#9

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