Learn Regular Expressions by Building a Spam Filter - Step 5

Tell us what’s happening:

Describe your issue in detail here.
You should use the assignment operator to set the textContent property of the result element.
but thats what im doing

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Learn Regular Expressions by Building a Spam Filter</title>
    <link rel="stylesheet" href="styles.css" />
  </head>

  <body>
    <header class="main-text">
      <h1 class="title">Is this Spam?</h1>
      <p class="description">
        Enter a phrase to check if it would be marked as spam or not.
      </p>
    </header>

    <main>
      <label class="message-label" for="message-input">Message: </label>
      <textarea
        placeholder="Enter message here"
        value=""
        type="text"
        name="message"
        id="message-input"
        rows="10"
        cols="40"
      ></textarea>
      <button class="btn" id="check-message-btn" type="button">
        Check message
      </button>
      <p id="result"></p>
    </main>

    <footer class="footer">&copy; freeCodeCamp</footer>
    <script src="./script.js"></script>
  </body>
</html>
/* file: styles.css */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --dark-grey: #1b1b32;
  --light-grey: #f5f6f7;
  --golden-yellow: #fecc4c;
  --yellow: #ffcc4c;
  --gold: #feac32;
  --orange: #ffac33;
  --dark-orange: #f89808;
}

body {
  background-color: var(--dark-grey);
  color: var(--light-grey);
}

body,
#message-input:placeholder-shown {
  text-align: center;
}

textarea {
  max-width: 90%;
}

.main-text {
  margin: 25px 0;
}

.title {
  font-size: 2.5rem;
}

.description {
  margin-top: 15px;
  font-size: 1.4rem;
}

.message-label {
  display: block;
  margin-bottom: 20px;
  font-size: 1.5rem;
}

#message-input:placeholder-shown,
textarea {
  font-size: 1.1rem;
}

.btn {
  display: block;
  cursor: pointer;
  width: 200px;
  margin: 10px auto;
  color: var(--dark-grey);
  background-color: var(--gold);
  background-image: linear-gradient(var(--golden-yellow), var(--orange));
  border-color: var(--gold);
  border-width: 3px;
}

.btn:hover {
  background-image: linear-gradient(var(--yellow), var(--dark-orange));
}

#result {
  font-size: 2rem;
  margin: 20px 0;
}

.footer {
  margin-top: 10px;
}
/* file: script.js */
const messageInput = document.getElementById("message-input");
const result = document.getElementById("result");
const checkMessageButton = document.getElementById("check-message-btn");

const isSpam = (msg) => false;


// User Editable Region

checkMessageButton.addEventListener("click", () => {
  if (messageInput.value === "") {
    alert("Please enter a message.");
    return;
  }
isSpam(messageInput.value) ? result.textContent += ' Oh no! This looks like a spam message.':result.textContent += " This message does not seem to contain any spam.";

});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Regular Expressions by Building a Spam Filter - Step 5

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

put this at the beginning of the line and the ternary operator to the left of the compound assignment operator

sorry didnt get it
isSpam(messageInput.value) ? result.textContent += ’ Oh no! This looks like a spam message.': result.textContent += " This message does not seem to contain any spam.";

you have not put result.textContent += at the beginning of the line

result.textContent += isSpam(messageInput.value) ?

result.textContent += ’ Oh no! This looks like a spam message.':

result.textContent += " This message does not seem to contain any spam."; my mind has stoped working

you should have result.textContent += only once, having it twice in an expression is a syntax error

1 Like

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

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=“”
}); it worked this way assignment operator was causing issue but instruction was to use asssignment operator.

1 Like

you need to use the assignment operator before the ternary, yes

1 Like

but i didnt use it and it worked .

what do you mean? = is the assignment operator

mybad i thought only += -= are assignment operators
Sorry

those are compound assingment, they do assignment and an other operation

1 Like

thank you so much for clarification.

Please advise, I’m hitting an error that states, "After your ternary, set the value of messageInput to an empty string:

const messageInput = document.getElementById("message-input");

const result = document.getElementById("result");

const checkMessageButton = document.getElementById("check-message-btn");

const isSpam = (msg) => false;

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 = '';

});
1 Like

Try using "" instead of ''

You have an extra space after the last expression in the ternary and the semicolon.

result.textContent = isSpam(messageInput.value) ? "Oh no! This looks like a spam message." : "This message does not seem to contain any spam." ; // <- space after the string and before semicolon.

It is kind of a bug with the regex.

1 Like

Thank you so much :slight_smile:

That was my first thought as well…