Basic JavaScript - Return Early Pattern for Functions

Tell us what’s happening:
my display return NaN instead of undefined in the console. should i use another method? my case is wrong?

Your code so far

// Setup
function abTest(a, b) {
  // Only change code below this line
switch(a,b){
  case a, b < 0:
  return undefined ;
  
}


  // Only change code above this line

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

console.log(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/114.0.0.0 Safari/537.36 OPR/100.0.0.0

Challenge: Basic JavaScript - Return Early Pattern for Functions

Link to the challenge:

This is not how a switch works

You could modify the switch statement so that it does work however. You can use true as a switch parameter and then put an a or b case inside it.
Or you could go for the simpler one-line if statement instead…

I went with “if” statement and it’s worked, thank you!
However i couldn’t figured out what you mean with use true as a switch parament

Its a cursed hack, but you can

switch (true) {
  case SomeConditionHere:
  case SomeOtherConditionHere:
}

But like I said, cursed code!

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