I am trying to toggle the display content of the page as well as the text on the button when the button is clicked. The if part of the statement works but not the else. Tried lots of different ways but still don’t understand why it’s not working?
let showBtn = document.querySelector('.timer-button');
showBtn.textContent = 'Break Timer'
function showTimer() {
if(showBtn.textContent) {
console.log('pressed 1')
sectionTwo.style.display = 'block';
sectionOne.style.display = 'none';
showBtn.textContent = 'Work Timer';
} else if(showBtn.textContent !== 'Break Timer') {
console.log('pressed 2')
sectionTwo.style.display = 'none';
sectionOne.style.display = 'block';
showBtn.textContent = 'Break Timer';
}
}
showBtn.addEventListener('click', showTimer);