Basic JavaScript: Return Early Pattern for Functions

Hello fellow campers,

I would like to find out the difference between the following codes , thank you!:

//This is my code which is wrong because it does not satisfy : abTest(-2,2) should return undefined

function abTest(a, b) {
  // Only change code below this line
  if (a < 0,  b < 0 )     // HOW  IS THIS LINE  BEING INTERPRETED W/ A   COMMA INSTEAD OF  A  "||" 
  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);

// SPOILER ALERT

// This is the right code :slight_smile:

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

3 Likes

Hello randelldawson,

Thank you for your feedback. It is quite helpful.

thanks man you just did me a big favor

The Right Code Is Here.

<redacted>

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.