Regex for Boolean

My project is not showing that my regex is passing for True. It’s only showing that my False are correct.

I don’t understand what I’m doing wrong. I’m not allowed to get the right answer from anyone but I am allowed to get help.

function telephoneCheck(str) {

const givMeDigitsBoy = (/"^([(]|^\b1?\s*|[0-9]+?[()-]?\s*)"/gi);

if (str !== givMeDigitsBoy.test(str)) {
    return false;
    } else if (str == givMeDigitsBoy.test(str)) {
        return true; 
    }
}

telephoneCheck("555-555-5555");

When you test using a regular expression, it returns only true or false. So you can’t have str !== givMeDigitsBoy.test(str)) because that will always return true since your string value will never be equal to true or false boolean values.

Instead you just want to have givMeDigitsBoy.test(str) in your if statement and then refactor at which point you return false and when you return true.

You can compress this function down into just one line of code but that is for another time.

Thanks for getting back to me Mr. Marcus.

I had gotten so down trying to figure things out that I had left the project alone for a couple days. I had to break things down into several variable regex expressions.

In addition, I found some good reading material to understand exactly what you are teaching me here., now. I am grateful for your response to my call for help. It means a lot.

I am, with great humor, stuck trying to make only one little test pass out of 29. I will get there. I’m sure of it.

Enjoy your evening.

What’s the challenge this is for, Sam?

This was for my Phone number validator project. I knew that the regex exp would get the answers quicker. I struggled joining the Boolean along with. I was either getting the Trues all right or the False.

Great news though. I just got this project completed. Fist pumps in the air!
I was very happy. It hurt me for a while and I thought, “Nah, there’s no way I’m going to be excited after finally finishing this one.”

But, alas, I was wrong.

Nice! I love to hear that. When you get through something like that, it feels amazing!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.