Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
JS issues in Brackets: Parsing error: unexpected token, expected an identifier

I'm new to javascript, I wanted to try to code a gallery page for my website. The script is supposed to cycle through the images in the list when the buttons are pressed and display the currently selected one in the middle of the page. I based this code off of a music player I found online, but for some reason I keep getting "parsing error: unexpected token" and "expected an identifier and instead saw 'let'". Here's the code:

let back_button = document.querySelector(".back-button");
let next_button = document.querySelector(".next-button");
let gallery_img = document.querySelector(".gallery-img");
let creation_date = document.querySelector(".creation-date");
let desc = document.querySelector(".desc");
let image_index = 0;
        
// Define the images to display
let image_list = [
    {
        name: "miku",
        date: "2-9-2021",
        desc: "",
        path: "Images/Art/2d/miku.png",
    },
    {
        name: "big dog",
        date: "8-26-2020",
        desc: "",
        path: "Images/Art/2d/big-dog.png",
    },
    {
        name: "good for ur soul",
        date: "8-26-2020",
        desc: "",
        path: "Images/Art/2d/good-for-your-soul.png",
    },
];
    
function loadImage(image_index) {
    //load a new image
    gallery_img.style.backgroundImage = "url(" + image_list[image_index].path + ")";
    
    //update details
    creation_date.textContent = "date created: " + image_list[image_index].date;
    desc.textContent = "description: " + image_list[image_index].desc;    
}
        
function nextImg() {
    //go back to the first img if the current one is last in the list
    if (image_index < image_index.length - 1)
        image_index += 1;
    else image_index = 0;
        
    //load the new image
    loadImage(image_index);
}
        
function prevImg() {
    //go back to the first img if the current one is last in the list
    if (image_index > 0)
        image_index += 1;
    else image_index = image_index.length - 1;
        
    //load the new image
    loadImage(image_index);
}
        
loadImage(image_index);

And here's the music player tutorial I based this off of.

I also tried directly copying all of the music player code (html, css, and js) to test if it was something wrong with my Brackets install/the original code, but it all worked perfectly, so it's probably because I missed something.

I tried adding /jslint es6:true/ to the top of the file too, but that didn't work either. The script is also set to load just before </body>, so I don't think it's that it's missing the document.

It's most likely because I missed something really stupid, but if anyone could help I would really appreciate it !! :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!