JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

please can someone tell me what is wrong in my code?
I think i got it all right but it’s not running in my browser. Please help me I’m confused right now.

Your code so far

function telephoneCheck(str) {
  const validPatterns = [ 
    // 555-555-5555
    /^\d{3}-\d{3}-\d{4}$/,
  
  // 1 555-555-5555
  /^1 \d{3}-\d{3}-\d{4}$/,

  // 1 555-555-5555
  /^1 \(\d{3}\) \d{3}-\d{4}$/,

  // 5555555555
  /^\d{10}$/,

  // (555)555-5555
  /^\(\d{3}\)\d{3}-\d{4}$/,

  // 1 555 555 55555
  /^1 \d{3} \d{3} \d{4}$/,

  // 1(555)555-55555
  /^1\(\d{3}\)\d{3}-\d{4}$/
  ]

  return validPatterns
  .some((patterns) => pattern.test(str));
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Link to the challenge:

What error are you getting in the console? Look closely at it and compare to your return line.

how do i do that? Please show me from my code

I’m not sure what you asking? Do you not see the error in the console pane?

You can see it yourself in your console panel.
image
Is that right?
Look at it closely.

the code you posted does not have function call. That may be the reason why you did not see the error mentioned in the post above.

Ahh, good catch. I just assumed that the poster left the function call there at the bottom and just forgot to paste it in.

And ya, they won’t see the reference error in the console pane when they run the tests, they need to have the console open in dev tools to see it.

Yes, but I actually do not know what to do there that’s why.
Please show me how I can correct it so I can learn more from there.

return validPatterns
  .some((patterns) => pattern.test(str));

Explain to us what this is doing. What is the reference error telling you is wrong about this?

return validPatterns
.some((patterns) => pattern.test(str));
}

I think am having a problem here because my console is pointing error here but i don’t know what to do.

Please help me out on this. What should i do?

The error says: pattern is not defined
Where do you initialise the pattern variable?

Please sir teach me what I should do here to run my test successfully.

Your some parameter is patterns but you are using pattern in the function body.

Please explain to us what the following code is doing:

return validPatterns
  .some((patterns) => pattern.test(str));

If you understand what it is doing then I think it will become clear what the reference error is saying.

1 Like

It was what I learned from YouTube tutorial that i applied

You should not copy YouTube tutorials about the freeCodeCamp projects. Doing so can lead to your certificate being revoked.

let names = ['bbsmooth', 'stormingpapa', 'JeremyLT']
// print all `names` to the console
// how would you do that?
// write code below

Oh whau, I had no clue people would need to do that… the whole purpose of FCC is to guide and teach us through interactive activities. What’s the point of copy pasting? This is not a course you need to do at school, or is FCC used for students officially?

sorry, I don’t copy, I learn and practice. point of correction