Image Changer only working once

So, i’m doing my first attempt at actually using some JavaScript on a web page. I’m making use of JS to cycle through several images when the user clicks 2 arrows. I’ve linked the CodePen page below so you can see the code and what im trying to do.

The problem I’m having is that this seems to only change the image once, then it stops working. Could someone explain what I’m doing wrong?

I’m using the number counter as a sort of visual cue to make sure it goes up and down depending on which arrow you click.

I understand that my JS is probably a bit longwinded for what I want it to do, but I figure this is something I’ll eventually change when I have a better understanding of JS.

Thanks all.

Right, I’ve juut solved this haha, I was missing the double ‘==’ within the ‘else if (imageNumber = 2)’

Now, another question then, what other ways could I write this code to make it less longwinded?

The other issue is that I have to click on the arrows 2x whenever I go from 5 -> 1 or 1 -> 5.

My best suggestion for sliders are to use Linked List.