<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
let color= ["white", "yellow", "aqua", "purple"]; // 배열 선언
let i = 0;
let changeColor = function () {
i++;
console.log(i)
let bodyTag = document.querySelector('body');
bodyTag.style.backgroundColor = color[i];
if (i === color.length-1) {
i = -1;
}
}
</script>
</head>
<body>
<!-- 버튼을 클릭하면 changeColor()함수 호출-->
<button onclick="changeColor();">배경 바꾸기</button>
</body>
</html>