var colors = ["black", "dimgray", "teal", "darkslategray", "darkgreen", "green", "crimson", "mediumvioletred", "royalblue", "midnightblue", "navy", "darkblue", "mediumblue", "blue", "sienna", "saddlebrown", "maroon", "darkorchid", "darkred", "darkviolet", "brown", "darkmagenta", "darkolivegreen", "firebrick", "purple", "indigo", "darkslateblue", "blueviolet", "slateblue"];
// 色コードの配列を作る
var colors = ["black", "dimgray", "teal", "darkslategray", "darkgreen", "green", "crimson", "mediumvioletred", "royalblue", "midnightblue", "navy", "darkblue", "mediumblue", "blue", "sienna", "saddlebrown", "maroon", "darkorchid", "darkred", "darkviolet", "brown", "darkmagenta", "darkolivegreen", "firebrick", "purple", "indigo", "darkslateblue", "blueviolet", "slateblue"];
// divを取得
var elements = document.querySelectorAll('div');
// div要素の数だけループする
for (var i = 0; i < divs.length; i++) {
// ランダムなインデックスを生成する
var index = Math.floor(Math.random() * colors.length);
// 色コードを取得する
var color = colors[index];
// 背景色を設定する
divs[i].style.backgroundColor = color;
};