<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>show number of character in given text</title>
</head>
<body>
<input type="text" name="" id="given_text">
<button onclick="character_sorting()">Click me</button>
<div id="result"></div>
<script>
function character_sorting (){
var text = document.getElementById('given_text').value;
var alphabet = {
a : 0,
b : 0,
c : 0,
d : 0,
e : 0,
f : 0,
g : 0,
h : 0,
i : 0,
j : 0,
k : 0,
l : 0,
m : 0,
n : 0,
o : 0,
p : 0,
q : 0,
r : 0,
s : 0,
t : 0,
u : 0,
v : 0,
w : 0,
x : 0,
y : 0,
z : 0
};
for(var i = 0; i < text.length; i++){
alphabet[text.charAt(i)] = alphabet[text.charAt(i)] + 1;
}
var result = "";
for (var k in alphabet){
result = result + k + " : " + alphabet[k] + "<br>";
}
document.getElementById('result').innerHTML = result;
}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>show number of character in given text</title>
</head>
<body>
<input type="text" name="" id="given_text">
<button onclick="character_sorting()">Click me</button>
<div id="result"></div>
<script>
function character_sorting (){
var text = document.getElementById('given_text').value;
var alphabet = {
a : 0,
b : 0,
c : 0,
d : 0,
e : 0,
f : 0,
g : 0,
h : 0,
i : 0,
j : 0,
k : 0,
l : 0,
m : 0,
n : 0,
o : 0,
p : 0,
q : 0,
r : 0,
s : 0,
t : 0,
u : 0,
v : 0,
w : 0,
x : 0,
y : 0,
z : 0
};
for(var i = 0; i < text.length; i++){
alphabet[text.charAt(i)] = alphabet[text.charAt(i)] + 1;
}
var result = "";
for (var k in alphabet){
result = result + k + " : " + alphabet[k] + "<br>";
}
document.getElementById('result').innerHTML = result;
}
</script>
</body>
</html>
No comments:
Post a Comment