// 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));
}
// Change values below to test your code
abTest(2, 2);
I tried that and when I get to the else statement the return statement
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); does not match up with the scope of the else. When I try to add another return statement into the else statement the output is nothing.
Correct code is,
if(a < 0 || b < 0){
return undefined;
}
Above code is defined return value when condition found true, undefined is JavaScript’s primitive types which does not required string sign to execute.
After trying for a while, I finally got it to work.
FIRST i had:
IF (a<0 || b< 0){
return;
}
This didn’t worked, but then I did this:
IF (a<=0 || b< =0){
return;
}
Then it worked, the only difference being <=.
for me using && did not work, and going to the detail the instructions say “Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.”
Even though && is saying “and” rather than “or” it accomplishes the same goal/means the same thing at the end of the day. Think of it this way: In order for (a > 0 && b> 0) to evaluate as true, it means BOTH a and b must be greater than zero – thus if one of those is less than zero, then the function will immediately exit with a value of undefined. You can almost always create and && that will produce the same result as an || and vica versa.