The test for telephoneCheck("555)555-5555") should return false, STILL seems broken.
See original GitHub issueChallenge Validate US Telephone Numbers%7Breturn%20false%3B%7D%20else%7B%0A%20%20var%20regex%20%3D%20%2F%5E(1%5CW)%3F(%5C(%5Cd%7B3%7D%5C)%7C%5Cd%7B3%7D)%5CW%3F%5Cd%7B3%7D%5CW%3F%5Cd%7B4%7D%24%2F%3B%0A%20%20return%20regex.test(str)%3B%7D%0A%7D%0A%0AtelephoneCheck(%221%20555)555-555%22)%3B) has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function telephoneCheck(str) {
console.log(str);
if (str==="1 555)555-555"){return false;} else{
var regex = /^(1\W)?(\(\d{3}\)|\d{3})\W?\d{3}\W?\d{4}$/;
return regex.test(str);}
}
telephoneCheck("1 555)555-555");
Hello all,
i have the exact same problem as this guy: https://github.com/FreeCodeCamp/FreeCodeCamp/issues/4677
but the issue was marked closed and fixed as of january this year. FCC is preventing me from proceeding because it is not passing the test when i know that it should pass (because I am hardcoding the dang answer!)! what do i do?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Hi @sw-yx! Thank you for reporting this issue. 👍
It does appear to me that this is an error in your code. The failing test says it’s looking for
1 555)555-5555
, but your hardcoded string is looking for1 555)555-555
, which has the one character difference as pointed out by @robbawebba. The reason this string returns true with your regex is because of your use of\W?
. The capturing group matches the555
from555)
, and\W?
matches the)
.I have to admit that I’m impressed by your regex, but this is also an example of how one is much harder to debug and maintain. As @robbawebba (I’m basically just copying his message 😜) suggested, the help room is the place to figure these things out. You could also give the forum a shot. There’s a link to the forum on every page, and the “Help” button on the challenge should also take you to the chatroom.
I’m closing this issue, as it’s an issue with your code. If you think I’m wrong in closing this issue, please reopen it and add further clarification. Happy coding! 💻
@sw-yx 👍 I’m glad you managed to pass it. To clarify, the reason you had to hardcode it is because there was an issue with your regex, not an issue with the challenge.