Build a Spam Filter - Step 17

Tell us what’s happening:

please i need help me code works but wont pass the test

Your code so far

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

const helpRegex = /please help|assist me/i;

// User Editable Region

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


// User Editable Region


const denyList = [helpRegex, dollarRegex];

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36

Challenge Information:

Build a Spam Filter - Step 17
https://www.freecodecamp.org/learn/full-stack-developer/workshop-spam-filter/step-17

What does the failing error message say? What have you tried to debug your code?

so this is the error message " Your dollarRegex must allow any number of spaces before the dollar quantity, and one or more spaces after

And this is my code:

const dollarRegex = /\s*[0-9]+\s+(hundred|thousand|million|billion)?\s+dollars/i;
const test1 = "1           hundred        dollars";
console.log(dollarRegex.test(test1)); // output: true

i need help

Replace the first literal space with the \s* expression. The \s character class matches whitespace, such as spaces, tabs, and new lines. The * quantifier means “match the previous character 0 or more times”.

Replace the second literal space with \s+. The + quantifier means “match the previous character at least one time”.

It looks like you made more changes than just these two.

really can you please point me to its direction

You could reset the code and then only make those two changes.

i still cant get it can you explain in a simpler term

reset the lesson twice now still cant get why the problem still exist

How many changes did you make to the code? If it is not two then you made too many changes.

1 Like

fixed it the starting dont need the whitespace