Skip to content

Commit f914707

Browse files
committed
character-counter added
1 parent 8a9d62a commit f914707

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

character-counter/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<link rel="stylesheet" href="styles.css">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Character Counter</title>
9+
</head>
10+
11+
<body>
12+
<div class="main">
13+
<h1>Character Counter</h1>
14+
<textarea name="character" id="character-set" rows="5" placeholder="Please write your text here..." maxlength="50"></textarea>
15+
<div class="stat">
16+
<h3>Total Characters: <span id="total-char">0</span></h3>
17+
<h3>Remaining: <span id="rem-char">50</span></h3>
18+
</div>
19+
</div>
20+
<script src="script.js"></script>
21+
</body>
22+
23+
</html>

character-counter/script.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const char = document.getElementById("character-set");
2+
const totalChar = document.getElementById("total-char");
3+
const remChar = document.getElementById("rem-char");
4+
5+
const counter = () => {
6+
totalChar.innerText = char.value.length;
7+
remChar.innerText = char.getAttribute("maxlength") - char.value.length;
8+
};
9+
10+
char.addEventListener("keyup", () => {
11+
counter();
12+
});
13+
14+
counter();
15+

character-counter/styles.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: black;
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
height: 100vh;
13+
}
14+
15+
16+
.main {
17+
width: 450px;
18+
max-width: 50%;
19+
min-width: 300px;
20+
background-color: rgb(31, 137, 229);
21+
padding: 1rem;
22+
border-radius: 10px;
23+
box-shadow: 0px 0px 20px rgba(255, 255, 255, 0.5);
24+
}
25+
26+
h1 {
27+
font-size: 1.5rem;
28+
text-align: center;
29+
padding: 1rem;
30+
}
31+
32+
textarea {
33+
width: 100%;
34+
border-radius: 10px;
35+
border: none;
36+
background-color: aliceblue;
37+
padding: 1rem;
38+
font-size: 1.2rem;
39+
}
40+
41+
h3{
42+
font-size: 1rem;
43+
font-weight: 500;
44+
45+
}
46+
47+
.stat {
48+
padding-top: 1rem;
49+
display: flex;
50+
justify-content: space-between;
51+
52+
53+
}
54+
55+
56+

0 commit comments

Comments
 (0)