Skip to content Skip to sidebar Skip to footer

Identifier Already Declared - Identifier 'userScore' Has Already Been Declared

Very new to JS and trying to create a Rock Paper Scissors game. I'm only just starting on the JS side of things and I am hitting an error on line 1 when declaring a const. I've see

Solution 1:

You are loading app.js into your HTML twice - once on the top of your file and then once again just before the end of your body. This will run the javascript twice and try to redeclare the const you've defined. const variables can not be redefined in javascript, which is why you are seeing this error.

This will actually happen to all of the variables you have defined, you're only seeing it happen on userScore because it happens to be the first variable declaration.

Answer : Remove one of the <script> tags that are loading app.js


Solution 2:

You have

<script src="app.js">

twice in your HTML. Once in the <head>, and again at the end of <body>.

The variables are all declared the first time it's loaded, so they're duplicates when you load it the second time.


Post a Comment for "Identifier Already Declared - Identifier 'userScore' Has Already Been Declared"