-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
33 lines (30 loc) · 1.08 KB
/
index.ts
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
let header = document.querySelector("#header") as HTMLHeadingElement;
let input = document.querySelector("#input") as HTMLInputElement;
let div = document.getElementById("container") as HTMLDivElement;
function getRandomColor() :string {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
const clicked = ():void => {
header.style.color = input.value;
header.innerHTML = input.value;
const c = input.value.split("").reverse().join("");
const rearrangedString = c.slice(-1) + c.slice(0, -1);
header.style.backgroundColor = rearrangedString;
div.style.backgroundColor = input.value;
};
const AnotherClick = ():void =>{
const hex = getRandomColor()
header.style.color = hex;
header.innerHTML = hex;
const reversedHex = hex.split("").reverse().join("");
const rearrangedString = reversedHex.slice(-1)+reversedHex.slice(0,-1);
header.style.backgroundColor = rearrangedString
input.value = hex;
div.style.backgroundColor = hex;
}
AnotherClick()