Hey, developers welcome to Day 24 of our 90Days 90Projects challenge. And in Day 24 we are going to create a Text & Word Counter using JavaScript
So to run this code you just need to copy the HTML and CSS code and run it into your code Editor.
Preview
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Text & Words Counter </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="counter-container">
<h2>Text & Words Counter</h2>
<textarea id="inputText" cols="10" rows="5" placeholder="Enter text here..."></textarea>
<div class="output">
<span id="char">0 Characters</span>
<span id="words">0 Words</span>
</div>
</div>
</body>
<script src="script.js"></script>
</html>
CSS Code
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: aqua;
}
.counter-container {
display: flex;
flex-direction: column;
text-align: center;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.6);
}
.counter-container,
textarea {
background-color: purple;
color: white;
}
.counter-container h2 {
font-size: 2rem;
margin-bottom: 1rem;
}
textarea {
border: none;
outline: none;
padding: 2rem 0;
text-align: left;
resize: none;
color: white;
}
.output {
display: flex;
justify-content: space-between;
}
JavaScript
const userText = document.getElementById('inputText')
const characters = document.getElementById('char')
const totalWords = document.getElementById('words')
userText.addEventListener('input', function () {
characters.innerHTML = userText.value.length + ' Characters';
totalWords.innerHTML = userText.value.trim().split(' ').length + ' Words'
})
brother please upload react js class
ReplyDeleteOk will do after some time
Delete