Something is wrong with my Menu button in slideshow pages!

Basically, I have a menu dropdown button triggered by the command on js:1 reading “let button = document.getElementById(“dropdown-button”);”. But whenever it’s on a page with a slideshow of images, an error pops up reading “script.js:1 Uncaught SyntaxError: Identifier ‘slideIndex’ has already been declared (at script.js:1:1)” and the button doesn’t work. How can I possibly fix this?

This means you’re declaring the variable “slideIndex” multiple times when you can only declare a variable once. If you need a different slideIndex for each slideshow, you should have a different name for it. If this makes no sense, share your Glitch project and I can show you line number about it.

I think I know what you’re talking about, but I already have different sldieshows with different names. I might have to share it with you.

Link: Glitch :・゚✧

Does the link work for you?

I hope you can help me soon. My assignment is due on Friday you see and I’m worried I might not be able to figure it out. I’ve tried fixing the problem like you said, but I see nothing else on the original js file that declares it twice.

looks like you’ve fixed it by renaming

it has this now though

image

Which page is that on? Also, the Menu still doesn’t work on the Creations or Graphic Design pages.

I saw that on the index page

That’s weird. That page doesn’t even use button2. Thankfully, it doesn’t seem to be harming anything else. What do you think it could be?

I just tried renaming the two button things on the javascript page. Didn’t seem to work though…

image

is it not working though?

So it’s working for you but not me? What type of OS are you using?

GNU/Linux :person_shrugging:

Damn. That’s not what I nor my college uses. How is this even happening? Are you sure that the menu thing works on both the Graphic Design and Creations pages on your end?

no, I only tried it on the index page

Can you please check and see if you can fic those two pages? Those are the ones I’m having a problem with.

oh, you know what, I think it’s declaring slideIndex both in the html <script> tag and in the script.js file

That’s what I think too. But when I try to delete them from either file, it disables the carousel. I want to try and have both the menu and carousel.

is that variable supposed to be shared?

and just to be sure, what do you mean by “delete them from either file”? I think we’re referring to changing code like this

let slideIndex = something;

to

slideIndex = something;

in whichever one comes later

Okay, so the error is gone on that page… but the button still doesn’t work.