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