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
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…
is it not working though?
So it’s working for you but not me? What type of OS are you using?
GNU/Linux
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.
And I did the same thing on the creations page, but that did the opposite for some reason. The menu works, but now the slides are disabled for some reason!
How is the error “dropdownbutton2?” Creations doesn’t use that button.
I’m getting this error when trying to use the slide buttons on the creations page
Uncaught ReferenceError: can’t access lexical declaration ‘slideIndex’ before initialization
plusSlides https://jackson-portfolio-fall-2023.glitch.me/script.js:35
onclick https://jackson-portfolio-fall-2023.glitch.me/creations.html:1
the dropdownbutton2 problem is coming from here
dropdownbutton2.addEventListener(“click”, open2);
line 19 in script.js
But like I said, Creations shouldn’t have to use anything from 19. What is it talking about?
Okay, I just made a change. Now it says that the problem is coming from slide 56. Graphic Design has the same problem as before…
but the line is still there, with nothing telling the browser “except don’t do this on the creations page,” so it tries and throws when it fails
Which are we talking about again? The script lines for the MENU button or the slideshows? I got distracted by my brother coming home.
the dropdownbutton2 problem on the creations page
Right. So um… what’s your plan/suggestion? I don’t want to have to scrap the carousel entirely. I need a js element as a requirement.
so you said you have until friday, how much time do you have to dedicate to fixing the scripts? we can try to come up with a plan that fits in that time budget
I have all day tomorrow, but I plan to mostly use it to finish up artwork I plan to post later this week and Christmas. But of course, this always comes first. So I think I can figure something out.
Want to meet tomorrow around 9?
I think we can focus on quick fixes. I don’t have time to meet though.
let’s discuss this line dropdownbutton2 thing. that code on line 19, is it needed on multiple pages?
Sorry, I was at work when you sent this.
ya no worries
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.