<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
display: -webkit-flex;
display: flex;
}
.sq{
width: 100px;
height: 100px;
border: 1px solid grey;
}
</style>
</head>
<body>
<div class="sq">Элемент 1</div>
<div class="sq">Элемент 2</div>
<div class="sq">Элемент 3</div>
</body>
<script>
var colors = [
'#ff0000',
'#00ff00',
'#0000ff'
];
document.getElementsByTagName('body')[0].onclick=e=>e.target.style.backgroundColor = colors[ Math.floor(Math.random() * colors.length)];
</script>
</html>