let
h, s, l,
min_s = 30, max_s = 70,
min_l = 70, max_l = 100;
h = Math.floor(Math.random() * 360); // 0-360 градусов цвета
s = Math.floor(Math.random() * (max_s - min_s) + min_s); // 30-70% насыщенности
l = Math.floor(Math.random() * (max_l - min_l) + min_l); // 70-100% яркости
document.body.style.backgroundColor = `hsl(${h}, ${s}%, ${l}%)`;
Так по-прежнему в переменнуюlet randomIndex = Math.floor(Math.random() * alphabet.length);
randomIndex
записывается случайный индекс. Один раз.const getRandomIndex = () => Math.floor(Math.random() * alphabet.length);
А вот функция, которая при каждом вызове getRandomIndex()
будет возвращать новый случайный индекс.