Learn Regular Expressions by Building a Spam Filter - Step 24

Tell us what’s happening:

Hi. I have passed this step by guessing, but I want to understand. I was confused by this hint:

3. Your freeRegex should use three character classes to match e and 3.

It’s the ‘three character classes’ part that is confusing me. Our original text is “free money”, which has two ‘e’ characters in it, so why do we need three character classes to replace it?
Are we checking for “freee money” or “fr3ee money” or any other combo? If so that’s arbitrary. Someone could get around our spam filter with 4+ 'e’s or '3’s. Am I misunderstanding something about character classes?
Thanks in advance.

Your code so far

/* file: script.js */
const messageInput = document.getElementById("message-input");
const result = document.getElementById("result");
const checkMessageButton = document.getElementById("check-message-btn");

const helpRegex = /please help|assist me/i;
const dollarRegex = /[0-9]+\s*(?:hundred|thousand|million|billion)?\s+dollars/i;

// User Editable Region

const freeRegex = /fre[e3]|[e3]|[e3] money/i;

// User Editable Region

const denyList = [helpRegex, dollarRegex, freeRegex];

const isSpam = (msg) => denyList.some((regex) => regex.test(msg));

checkMessageButton.addEventListener("click", () => {
  if (messageInput.value === "") {
    alert("Please enter a message.");
    return;
  }

  result.textContent = isSpam(messageInput.value)
    ? "Oh no! This looks like a spam message."
    : "This message does not seem to contain any spam.";
  messageInput.value = "";
});

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Spam Filter - Step 24

Hi there!

free money have 3 e characters. You need to add character class for each one.

3 Likes

Hahahahaha wow. I can’t believe I missed that, thank you.

In that case I think there is a bug, because the test accepts this as an answer:

const freeRegex = /fre[e3]|[e3]|[e3] money/i;

That should be reported on GitHub freecodecamp curriculum repository.

You say yours accepted that? I’ve been struggling with this one, I have exactly what you have, and I have also tried it with only just two as it is supposed to be and it won’t accept either of them.

Yes, I just checked again right now and it is still accepted. However, please note even though it’s accepted this is the WRONG answer.

The correct solution, which I didn’t realize the first time because I had tunnel vision, is that there are two e’s in free and one in money :smile:
So three total.

Sorry I haven’t reported it on github yet, will do that now.

I have just made a post on GitHub

1 Like

I must have had a typo somewhere that I just couldn’t see or something because I copy and pasted what you had typed out previously and it gave me the pass. I don’t even know at this point.