Welcome back, @albaraa_1949
Congratulations! Your code works as expected!
I have just two possible simplifications:
- Since the only difference in the image names are the number from 1 to 5, you could get rid of the array and just use a loop variable that goes from 1 to 5 to build the
src
valuesnewImage.setAttribute('src', `https://raw.githubusercontent.com/albaraa-1949/images/main/pic${i}.jpg`);
- To set
displayedImage.src
you could pass the event object to the function and use its src
instead of writing the URL again.newImage.onclick = function(e) {
displayedImage.src = e.target.src;
}
Please tell me if my explanations aren’t clear and keep up the good work.
Happy coding!
Michael