-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite4.html
53 lines (53 loc) · 1.48 KB
/
site4.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
48
49
50
51
52
53
<DOCTYPE! html>
<html>
<head>
<style>@import "./site4.css"</style>
<title>SITE 4</title>
</head>
<body>
<h1>Convert the string</h1>
<div id="instruction">
Convert the input string as follows:
<ul>
<li>Reduce upper case letters to lowercase</li>
<li>Rotate letter to the previous letter</li>
<li>Then replace each vowel with uppercase vowel</li>
</ul>
Example: "Great To Meet You!" converts to "fqdzs sn ldds xnt!"
</div>
<div>
<p><input type="text" id="user_input" /></p>
<p><span id='display'></span></p>
<p><button onClick="convertString()">Submit</button></p>
</div>
</body>
<script>
console.log('hey');
function convertString (){
var arr = Array.prototype.slice.call(document.getElementById("user_input").value);
var ans = '';
var vowels = {'a': 'A', 'e': 'E', 'i': 'I', 'o': 'O', 'u': 'U'};
var dict = 'abcdefghijklmnopqrstuvwxyz';
arr.forEach(function(elem){
var tmp = elem.toLowerCase();
var idx = dict.indexOf(tmp);
var ltr;
if(idx !== -1){
if(idx === 0){
ltr = dict[25];
} else {
ltr = dict[idx - 1];
}
if(vowels.hasOwnProperty(ltr)){
ltr = vowels[ltr];
}
} else {
ltr = elem;
}
ans += ltr;
});
document.getElementById('display').innerHTML = ans;
}
</script>
</html>
</DOCTYPE!>