-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.html
54 lines (52 loc) · 1.62 KB
/
color.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
54
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body {
height: 300px;
width: 500px;
margin: 100px auto;
background-color: antiquewhite;
}
</style>
</head>
<body>
<label for="colorname"> Enter Text </label>
<input type="text" id="text" />
<button onclick="change()">Submit</button>
<button onclick="reverse()">reverse</button>
<button onclick="capitalize()">capital</button>
<div id="color" style="height: 130px; width: 180px"></div>
<script>
function change() {
var color = document.getElementById("text").value;
document.getElementById("color").style.backgroundColor = color;
}
function reverse() {
var text = document.getElementById("text").value;
var rev = text.split("");
var str;
for (let i = 0; i < rev.length / 2; i++) {
let temp = rev[i];
rev[i] = rev[rev.length - 1 - i];
rev[rev.length - 1 - i] = temp;
}
rev = rev.join(""); // back to string
document.getElementById("color").innerHTML = rev;
}
function capitalize() {
var text = document.getElementById("text").value;
var words = text.split(" ");
for (var i = 0; i < words.length; i++) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
}
words = words.join(" "); // Combine capitalized words and return
document.getElementById("color").innerHTML = words;
}
function capital() {
var text = document.getElementById("text").value;
}
</script>
</body>
</html>