Hi, So I’m learning javascript and I’m stuck in a function here. I’m doing a landing page functionality with pure javascript and not allowed to use any libraries. I want to make a link on scroll to a specific section to be active. so I did a helper function IsInViewPort() to sense the position when I’m scrolling the page. I’m trying to make a function that is on scrolling, Looping inside the sections in the page to add the specified section to the classList and make its link from navbar active. when I added this function there was an error says “unexpected identifier” and the navbar disappeared. how to fix it?
the function with the issue:
`window.addEventListener(“scroll” , e=>{
for(let i=1 ; i<=sections.length;i++){
if(isInViewport(sections[i])){
sections[i].classList.add(“your-active-class”);
document.getElementsByClassName([i].id}`)[0].classList.add(“active”);
}
else{
section.classList.remove(“your-active-class”);
document.getElementsByClassName([i].id}`)[0].classList.remove(“active”);
}
}
the codepen with the full code:
I appreciate your help. I need help asap.