can anyone help me with this error i got in my script while makinga a hamburger menu on a websit

55 Views Asked by At

code:

let bar = document.querySelector('.bars'),
navItem = document.querySelector('.nav-items');
bar.addEventListener('click', () => {
    navItem.classList.toggle('active');
})

issue:

JsLint:
expected an indentifier and instead saw 'let'. let bar = document.querySelector('.bars'),


ESLint:

ERROR: Parsing error; Unexpected token bar let bar = document.querySelector('.bars'),

ERROR: Parsing error; Unexpected token ) let bar = document.querySelector('.bars'),

so the hamburger menu displays correctly

1

There are 1 best solutions below

0
ruffin On

Whenever you catch yourself wondering if JSLint is operating correctly, I'd suggest trying your code on jslint.com.

This lints there:

let bar = document.querySelector(".bars");
let navItem = document.querySelector(".nav-items");
bar.addEventListener("click", function () {
    navItem.classList.toggle("active");
});

There were several things I needed to change to make your code lint, but let was not one of them. More on es6 and JSLint here.

That means, exactly as the commenters have said, that you're seeing this issue because you're not using the latest version of JSLint -- as in you're waaaaay behind. You're at least three years behind, it appears.

You'll need to either push your code back to es5 (var bar = document.querySelector(".bars");) or update your linter.