Is that all your code ?
I am beginner but for the little I know the problem come from this part :
if(mysrc===i.jpg)
What is i.jpg ? I guess you wanted yo use a counter that become “1.jpg”, “2.jpg” etc. But none is declared. Furthermore I am not sure il would work like this. Maybe you should try to put “.jpg” between quote marks and concatenate it with i.
Back tracking to what Meditsh stated, JS is trying to look for the property i.jpg, you would need to wrap it in quotes if you are trying to compare against a string, or concatenate the i, if it’s a counter to the string “jpg”. If it’s the second issue, I would recommend using template string literals instead, as it’s easier to read and understand.