I have a code when a timer is shown and removed using 2 functions repeatedly by using SetInterval. However when the timer is finished I am trying to clear the SetInterval With ClearInterval but this is not working. When setInterval and ClearInterval set outside gettimer function the they work properly as well. Can someone help?
>declaring const M1 and M2
let M1, M2
>functions
function ShowScrollBar(){
ScrollContainer.classList.add('show-scroll-container')
}
**function TimeShowscrollBar(){
M1 = setInterval(ShowScrollBar,3000)
}**
function RemoveScrollBar(){
ScrollContainer.classList.remove('show-scroll-container')
}
**function TimeRemovecrollBar(){
M2 = setInterval(RemoveScrollBar,6000)
}**
**function ClearTimeShowscrollBar(){
clearInterval(M1)
}
function ClearTimeRemovecrollBar(){
clearInterval(M2)
}**
function gettimer(){
const futureTimems = ClosingDate.getTime()
const presentTimems = new Date().getTime()
const RemainingTimeSec = (futureTimems-presentTimems)/1000
if(RemainingTimeSec>=0){
window.addEventListener('DOMContentLoaded', function(){
popup.classList.add('showpopup')
popup.classList.remove('popup')
})
}
ClosePopupBtn.addEventListener('click',function(){
popup.classList.remove('showpopup')
popup.classList.add('popup')
>setInterval containing functions working properly
**TimeShowscrollBar()
TimeRemovecrollBar()**
})
if (RemainingTimeSec<=0){
clearInterval(countdown)
>Functions with clearInterval not working here
**ClearTimeShowscrollBar()
ClearTimeRemovecrollBar()**
timing.forEach(function(contenu, MVindex){
contenu.innerHTML = '00'
})
timingS.forEach(function(contenu, MVindex){
contenu.innerHTML = '00'
})
popup.classList.remove('showpopup')
popup.classList.add('popup')
}
}
let countdown = setInterval(gettimer,1000)
gettimer()