Trying to return early patterns in functions

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

abTest(2,2);

the script is not returning “undefined” as an exit.

Give this lesson a quick review:

Also, please refer to the hint in the lesson about undefined because you’ve got a problem there as well.

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

abTest(2,2);

so what do i use instead of a string

undefined, it’s a value just like 0 or "hello"

undefined   // this is the primitive value undefined
"undefined" // this is a string

there is a problem in comparing.
2< 0
this is NOT possible
is undefined

You can certainly check if 2 < 0. That expression evaluates to false.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.