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.
Remove the extra script element
<script src="scripts/randomize-film.js"></script>