Test background js

by Nik Shevchenko

HTML

<a href="#" class="button">Click here</a>
<div class="frame"></div>

CSS

body {
  background: #f0f0f0;
  padding: 50px;
}

.button {
  text-decoration: none;
  text-transform: uppercase;
  color: red;
}

.frame {
  border: 3px solid #000;
  width: 100px;
  height: 100px;
  margin-top: 20px;
}

JavaScript

var link = document.getElementsByClassName('button')[0];
var frame = document.getElementsByClassName('frame')[0];

link.onclick = function() {
	var R = Math.floor(Math.random() * (255 + 1));
  var G = Math.floor(Math.random() * (255 + 1));
  var B = Math.floor(Math.random() * (255 + 1));
  frame.style.backgroundColor = 'rgb(' + R + ', ' + G + ', ' + B + ')';
  frame.style.borderColor = 'rgb(' + G + ', ' + B + ', ' + R + ')';
  document.body.style.backgroundColor = 'rgb(' + B + ', ' + G + ', ' + R + ')';
};