Build a Real Time Counter - Build a Real Time Counter

Tell us what’s happening:

Hi FCC staff,
Looks like the 6th (last) test has a bug. Although my solution works as expected, the last test does not pass, maybe because its checking for one specific solution instead multiple other possibilities.
Could please check this once?
Thanks

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
      rows="10"
      cols="50"
      id="text-input"
      placeholder="Type something..."
          

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

</body>


</html>
/* file: script.js */
const charCount = document.getElementById("char-count");
const textInput = document.getElementById("text-input");
let count = 0;
textInput.addEventListener("input", (e) => {
  console.log(e.target.value);
  count = e.target.value.length;
  charCount.innerText = `Character Count: ${count}/50`;
  if (count === 50) {
    charCount.style.color = "red";
        textInput.setAttribute("maxLength", "50");

  }
});

/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build a Real Time Counter - Build a Real Time Counter

There is a bit of a hidden requirement here.

Add a console.log to your code to check how many characters there are, so you can see what the tests are doing. If the test puts more than 50 characters into that variable your code needs to remove the extra characters and bring it back down to 50.

1 Like

You can simulate what the test does by pasting in the text input.

Like, if I paste in 100 characters, there are 100 characters:

1 Like

Thanks, now it passed. But the test is indeed sneaky.

1 Like