const body = document.querySelector('body', 'body.background')
const img1 = document.querySelector('#img1', '#img1.display')
const img2 = document.querySelector('#img2', '#img2.display')
const p1 = document.querySelector('#p1', '#p1.display')
const p2 = document.querySelector('#p2', '#p2.display')
const bt1 = document.querySelector('#bt1', '#bt1.display')
const p3 = document.querySelector('#p3', '#p3.display')
const bt2 = document.querySelector('#bt2', '#bt2.display')
const img3 = document.querySelector('#img3', '#img3.display')
const p4 = document.querySelector('#p4', '#p4.display')
const slider = 1;
img1.onclick = function(){
p1.style.display = 'none'
img1.style.display = 'none'
img2.style.display = 'block'
bt1.style.display = 'block'
}
bt1.onclick = function(){
img2.style.display = 'none'
bt1.style.display = 'none'
p3.style.display = 'block'
bt2.style.display = 'block'
slider = 2;
}
bt2.onclick = function(){
bt2.style.display = 'none'
p3.style.display = 'none'
img3.style.display = 'block'
p4.style.display = 'block'
let color = ['red','purple'];
let colorIteraion = 0;
function colorFunction(){
if ( colorIteraion >= color.length) colorIteraion = 0;
document.body.style.background = color[colorIteraion];
colorIteraion++;
}
setInterval(colorFunction,500);
slider = 3
}
const back = document.querySelector('#back', '#back.display');
back.onclick = function(){
if (slider == 1){
body.style.background = 'red';
}
if (slider == 2){
body.style.background = 'blue';
}
if (slider == 3){
body.style.background = 'black';
}
}
Как сделать постоянное обновление переменной slider?