Tell us what’s happening:
I can solve the problem with the if statement but I was wondering why it doesn’t work with the switch.
Your code so far
// Setup
function abTest(a, b) {
// Only change code below this line
switch(a,b){
case a<0:
case b<0:
return undefined;
break;
default:
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
break;
}
}
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/87.0.4280.88 Safari/537.36 OPR/73.0.3856.329.
hello. I did some browsing and if you replace the statement in your switch with true, like switch(true): it will run the code as intended
Also, you dont have to put break; after a return statement, as it breaks the loop by default
Is general, I’m not a big fan of using a switch like that. A switch is for comparing one valuable to many possibilities. An if-else is for more complex comparisons.
Side note: it’s really best to use indentation for readability and maintainability. It’s good to get in the habit now while you are on the less complex lessons so that others can read your code in future lessons of you have any questions.