button
by Dylan Schadeck
HTML
<html>
<head>
<title>Title</title>
</head>
<body>
<button id="toggler">Click Me</button>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
JavaScript
const colorClosure = () => {
const colors = ['pink', 'red', 'orange', 'blue'];
let count;
(count === undefined || count === colors.length - 1) ? count = 0 : count++;
document.body.style.background = colors[count];
}
}
const button = document.getElementById('toggler');
const innerColorClosure = colorClosure();
button.addEventListener('click', innerColorClosure)