Tell us what’s happening:
I am trying to complete this challenge by following the instructions which are as follows:
" Modify the function abTest
so that if a
or b
are less than 0
the function will immediately exit with a value of undefined
.
I thought that was simple enough so I solved it like shown in the code. However this lets me pass only two of the test parameters:
-abTest(-2,2)
should return undefined
-abTest(2,-2)
should return undefined
which it does. But the test asks for all of the parameters to be met in order to be able to proceed to the next one. Those parameters are as follows:
-abTest(2,2)
should return a number
-abTest(2,2)
should return 8
-
abTest(2,8)
should return18
-abTest(3,3)
should return12
-abTest(0,0)
should return0
How can I modify the function in a way that all of those can evaluate to the appropriate return values at the same time?
Any kind of help would be greatly appreciated!
Your code so far
// 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));
}
console.log(abTest(2,2));
// 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));
}
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/83.0.4103.61 Safari/537.36
.
Challenge: Return Early Pattern for Functions
Link to the challenge: