Tell us what’s happening:
Hi, is this not doing what the test demands? I’m failing test #6.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<main>
<div id="text-container">
<p id="char-count">Character Count: 0/50</p>
<textarea id="text-input"></textarea>
</div>
</main>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
#text-area {
width: 200px;
max-width: 400px;
height: 100px;
max-height: 400px;
margin-top: 20px;
font-size: 16px;
padding: 10px;
box-shadow: 0 4px 8px rgba(255, 252, 252, 0.1);
font-family: Arial, Helvetica, sans-serif;
}
div {
display: flex;
flex-direction: column;
align-items: center;
}
.capped {
color: red;
}
/* file: script.js */
const textArea = document.getElementById("text-input");
const textDisplay = document.getElementById("char-count");
textArea.addEventListener("input", () => {
const currentLength = textArea.value.length;
textDisplay.textContent = `Character Count: ${currentLength}/50`;
if (currentLength >= 50) {
textDisplay.classList.add("capped");
textArea.value = textArea.value.substring(0, 49);
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0
Challenge Information:
Build a Real Time Counter - Build a Real Time Counter
