question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The test for telephoneCheck("555)555-5555") should return false, STILL seems broken.

See original GitHub issue

Challenge 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:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
systimoticcommented, Nov 21, 2016

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 for 1 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 the 555 from 555), 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! 💻

0reactions
systimoticcommented, Nov 22, 2016

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Telephone # Validator - JavaScript - The freeCodeCamp Forum
The one failing test is this one: telephoneCheck("55 55-55-555-5") should return false. After you create your polishedPhone variable ...
Read more >
JavaScript Projects - Telephone Number Validator - CodePen
Return true if the passed string looks like a valid US phone number. ... Test Examples: ... telephoneCheck("1 555)555-5555") should return false.
Read more >
Why does the following program return incorrect boolean ...
But for some inputs, it returns invalid boolean values. Why is that ? Inputs: "1 (555) 555-5555" should return true, but actually returns...
Read more >
100 Days of Code: Day 60 - Blissful Lemon
I changed one line of code and poof all the tests passed. ... { return true; } else { return false; } }...
Read more >
Telephone Validator - Project 4 Javascript Certification ...
Solutions: https://github.com/yazeedb/FCC-Algos-and-DS-SolutionsRegex tester: https://www.regexpal.comMy personal site: https://www.yazeedb.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found