-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
47 lines (41 loc) · 1.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta description="" author="" content="">
<link rel="stylesheet" href="index.css">
<title>ASCII Converter</title>
</head>
<body>
<marquee class="marq">Word to ASCII Converter</marquee>
<div class="main">
<label for="inputWord">Enter a word or phrase:</label><br>
<input type="text" id="inputWord" placeholder="Type here...">
<button onclick="convertToASCII()">Convert</button>
<button onclick="clearOutput()">Clear</button>
<h2>ASCII Codes:</h2>
<p id="asciiOutput"></p>
</div>
<!-- Functionality -->
<script>
function convertToASCII() {
const input = document.getElementById('inputWord').value;
let asciiCodes = '';
for (let i = 0; i < input.length; i++) {
asciiCodes += input.charCodeAt(i) + ' ';
}
document.getElementById('asciiOutput').textContent = asciiCodes.trim();
}
function clearOutput() {
document.getElementById('asciiOutput').textContent = '';
document.getElementById('inputWord').value = '';
}
document.getElementById('inputWord').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
convertToASCII();
}
});
</script>
</body>
</html>