forked from justEhmadSaeed/random-gradient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (29 loc) · 944 Bytes
/
script.js
File metadata and controls
34 lines (29 loc) · 944 Bytes
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
const h3 = document.querySelector('h3');
const color1 = document.querySelector('.color1');
const color2 = document.querySelector('.color2');
const body = document.querySelector('#gradient');
const random = document.querySelector('button');
setGradient = () => {
body.style.background = _linearGradient();
random.style.background = _linearGradient();
h3.textContent = `${body.style.background}`;
};
_linearGradient = () => {
return 'linear-gradient(to right,' + color1.value + ', ' + color2.value + ' )';
};
color1.addEventListener('input', setGradient);
color2.addEventListener('input', setGradient);
////Roshaan made these Changess
randomColor = () => {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
random.addEventListener('click', () => {
color1.value = randomColor();
color2.value = randomColor();
setGradient();
});