-
Notifications
You must be signed in to change notification settings - Fork 0
/
changecolor.html
38 lines (34 loc) · 914 Bytes
/
changecolor.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Gerador randomico de background</title>
<style>
button {
margin: 10px;
}
</style>
</head>
<body>
<button>Mude a cor!</button>
<script>
var btn = document.querySelector('button');
console.log('criou a variável btn');
function num (){
var min = Math.ceil(1);
var max = Math.floor(255);
console.log('gerou numero');
var nu = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(nu);
return nu;
}
function bgChange() {
var rndCol = 'rgb( ' + num() + ', ' + num() + ', ' + num() + ')';
document.body.style.backgroundColor = rndCol;
console.log(rndCol);
}
btn.addEventListener('click', bgChange);
</script>
</body>
</html>