Iam following a code to make a quiz.Iam building a function to highlight one list item and add a class to it.
enter code here
function chooseAnswer(){
answer.querySelectorAll('li').forEach((option)=> {
option.addEventListener('click',()=>{
if(answer.querySelector('.selected')){
let activeAnswer=answer.querySelector('.selected');
activeAnswer.classList.remove('selected')
}else
option.classList.add('selected')
})
The code is working but i do not understand the if condition from the source. Can someone help?