-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_2.html
More file actions
76 lines (74 loc) · 2.63 KB
/
task_2.html
File metadata and controls
76 lines (74 loc) · 2.63 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<input
type="text"
value=""
placeholder="Add string value"
name="operator"
id="input"
/>
<h3 id="answer"></h3>
<button type="button" id="submit" onclick="Reverse()">
Reverse the string
</button>
<button type="button" id="submit" onclick="Vowels()">
Count the No of Vowels
</button>
<button type="button" id="submit" onclick="spaces()">
Remove all spaces
</button>
<!-- --------------------- -->
<script>
function Reverse() {
var input = document.getElementById("input").value;
var answer = document.getElementById("answer");
var str_split = input.split("");
var check = str_split.reverse();
alert(check);
// var array = [];
// for (let a = str_split.length - 1; a >= 0; a--) {
// // const element = input.split('').reverse().join('');
// var element = str_split[a];
// array.push(element);
// }
// var str_arr = array.join("");
// answer.innerText = "Reverse stirng: "+str_arr;
}
// <!-- --------------------- -->
function Vowels() {
var input = document.getElementById("input").value;
// var vowels = input.match(/[aeiouAEIOU]/g);
// var vowelCount = vowels ? vowels.length : 0;
var answer = document.getElementById("answer");
var str_split = input.split("");
var count_vowl = 0;
var array = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"];
for (var a = 0; a < str_split.length; a++) {
for (var b = 0; b < array.length; b++) {
if (str_split[a] == array[b]) {
count_vowl = count_vowl + 1;
} else {
continue;
}
}
}
answer.innerText = "No of Vowels: " + count_vowl;
}
// <!-- --------------------- -->
function spaces() {
var input = document.getElementById("input").value;
var str_split = input.split(" ");
// var str_arr = input.replace(/\s+/g, "");
var str_arr = str_split.join("");
var answer = document.getElementById("answer");
answer.innerText = "Remove all space: "+str_arr;
}
</script>
</body>
</html>