Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda