Build a Real Time Counter - Build a Real Time Counter

Tell us what’s happening:

My code is passing every other test but it doesn’t pass this: If character count is greater than or equal to 50, the extra input should be trimmed. And I don’t know why :tired_face::tired_face:

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Real Time Counter</title>
</head>

<body>
<textarea name="text" id="text-input"></textarea>
  <p id="char-count">Character Count: 0/50</p>
  <script src="script.js"></script>
</body>


</html>
/* file: styles.css */

/* file: script.js */
    let text = document.getElementById("text-input")
    let para = document.getElementById("char-count")

    
    text.addEventListener("input", () => {
        text.maxLength = 50
      para.textContent = `Character Count: ${text.value.length}/50`
      if (text.value.length >= 50) {
        para.style.color = "red"
        para.textContent.trim()
      }
    })

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:157.0) Gecko/20100101 Firefox/157.0

Challenge Information:

Build a Real Time Counter - Build a Real Time Counter

GitHub Link: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/lab-real-time-counter/66bb3e20d3dc5b6d0a21f5dd.md

Hi @Richmond_otache,

If I paste the below text into the textarea, I see all of that text and "Character Count: 101/50’ is displayed in red.

Here is some text that is more than 50 characters long and should be truncated to just 50 characters.

The text in the textarea is not being limited to a maximum of 50 characters.

Happy coding

On my code editor it doesn’t pass 50 words actually but on freecodecamp it passes 50

All this line of code is doing is removing white space from the beginning and end of the text in the textarea element; it is not deleting characters that exceed the maximum length of 50 characters.

it’s not even doing that, because trim returns a new value, does not change the value it is called on

Good point! And para isn’t referencing the text in the text area anyway.

Did you overlook this instruction not to use the maxlength attribute? And would this work to limit the number of characters to 50 if the full text is pasted into the textbox?

NOTE: While the maxlength attribute would achieve the correct functionality, this lab requires a JavaScript only solution.