Challenge Return Early Pattern for Functions has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
// 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(3,3);
Instructions was:
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 cant move to next chapter pls help
@mallikarjun92, undefined
should not be string, remove double quotes. And next time, if you have problems with your code, please, post a message in our Gitter chat room first, thanks.
thanx!
This is kind of a silly wording of the question.
Instructions
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 would assume this means (a || b > 0);
Wouldn't it make more sense to say "a as well as b are less than 0", which would be (a > 0 || b > 0);?
It's weird...
I tried putting (a || b < 0) but that doesn't work.
Wonky...
so you have to put it in the long way: (a < 0 || b < 0)
@mukai154 I had the same thing!
this is how i go past that waypoint
// Setup
function abTest(a, b) {
// Only change code below this line
if (a < 0 || b < 0){
return undefined;
} else {
// 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);
@topklar I literally had the same exact solution as yours, but kept getting syntax error. Mine just had different spacing and line breaks. I copied/pasted yours, and it worked....This problem needs revision.
I tried using this approach and it didn't work. I believe this is supposed to be correct
// Setup
function abTest(a, b) {
// Only change code below this line
if ((a || b) < 0){
return undefined;
} else {
// 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);
@JideLambo
Please use the HelpJavaScript chat room for getting challenge related help.
Happy Coding.
_removed solution by mod_
@killgrey, Please do not post your solution on here. You could help people at FreeCodeCamp Chat Room or Forum. GitHub Issues are for reporting bugs on the website only.
Happy Coding!
@texas2010
The chat is so messy, and . have so much smartasses you can't get help there.
I agree--that chatroom is a complete disaster. Why can't there just be a chat or forum page for each challenge?
Thank goodness I'm not alone, I thought I was dumb for trying (a || b < 0)
Okay.. But why is (a < 0 || b < 0) better than ((a || b) < 0)? At least to this noob, they do the same thing.
Guys, I know this is not the medium as you should be using the chat room, but I see so many people here doing the same thing, so I wanted to point this out.
Remember that when you use the logical operators, you are actually setting multiple conditions and they evaluate to true or false.
Example: if (a || b < 0) return undefined;
that actually evaluates to if A==TRUE OR b IS LESS THAN 0
which is not the solution you are looking for. if ((a||b)<0)
simply isn't a valid conditional statement.
Hope this helps.
_Mod: The only reason I posted this is because this page is a top Google result for this question and it will likely never die, so my example above is only a hint, not the solution._
The Solution is below:
removed solution by mod
Most helpful comment
I agree--that chatroom is a complete disaster. Why can't there just be a chat or forum page for each challenge?