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

188
Visualizações
Why am I getting a 'Uncaught SyntaxError: Identifier 'randFilmIndex' has already been declared' error?
    function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min) + min);
}

 function arrayRemove(arr, value) { 
    
        return arr.filter(function(ele){ 
            return ele != value; 
        });
}

// Define film list
filmList = ['film1', 'film2', 'film3'];

let randFilmIndex = getRandomInt(0, filmList.length);
let randFilm = filmList[randFilmIndex];
filmList = arrayRemove(filmList, randFilm);

document.getElementById('option1').innerHTML = randFilm;

Why does this code give the error

Uncaught SyntaxError: Identifier 'randFilmIndex' has already been declared (at randomize-film.js:1:1)

when I run it?

I'm using codecademy workspace, and my html is

<!DOCTYPE html>
<html>
<head>
  <title>Rotten Tomatoes</title>
  <meta name="viewport" content="width=device-width,initial-scale=1" >
  <link href="style.css" rel="stylesheet">

  <!-- Scripts -->

  <script src="scripts/randomize-film.js"></script>
</head>
<body>
  <center>
    <h1 class="title">Rotten Tomatoes Game</h1>
    <a href="rules.html"><h3>Click here to learn the rules</h3></a>
    <ul class="buttons">
      <a href="you-picked-x-film.html"><li id="option1">Option 1</li></a>
      <a href="you-picked-x-film.html"><li id="option2">Option 2</li></a>
    </ul>
  </center>

  <script src="script.js"></script>
</body>
<!-- Scripts -->

<script src="scripts/randomize-film.js"></script>

</html>

Can you help me discover what the problem is? I'm trying to make a rotten tomatoes game.

My OS is Linux and browser is Chromium, but that shouldn't matter.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Remove the extra script element

<script src="scripts/randomize-film.js"></script>
about 4 years ago · Juan Pablo Isaza Relatório
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