Hi there, can someone explain to me what I’m missing?
Here’s my code so far for this challenge:
// Setup
function abTest(a, b) {
// Only change code below this line
if (a < 0 || b < 0);
return;
if (a > 0 && b > 0);
return (a*b) + a;
if (a == b);
return (a*2*b);
// 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);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.
The challenge asks you to return if a or b is less than 0. Otherwise just do the calculation that is already present.The challenge does not ask you to do any of these things, not sure why you added them:
if (a > 0 && b > 0);
return (a*b) + a;
if (a == b);
return (a*2*b);
Hey Guys, i was trying to do this challenge, but i don’t get how they got 8 on abTest(2,2)
Math.pow(Math.sqrt(a) + Math.sqrt(b), 2). according to my knowledge back to C, that expression is equal to squareroot of a+ squareroot of b power 2(didn’t get math sign)
can anyone tell me where am wrong
Ooh now get it. were trying to eliminate squareroot inside the equation. thanks buddy
what about the return?? still getting some trouble with return 0, return 1 and return only.
Do you mean the return on the line of that mathematical expression?
It returns the result of Math.pow rounded to the nearest integer (Math.round is the one that makes the rounding - it is needed because of limitations of doing this operations in binary with a limited number of bits available)