Assessment wanted for gallery

I have completed the “Image gallery” test, and I would like to get the evaluation.
Thank you in advance :slightly_smiling_face:

Test link : https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Image_gallery .

Code link: https://codepen.io/someone_49/pen/dyzmmJY .

Welcome back, @albaraa_1949 :wave:

Congratulations! Your code works as expected! :medal_sports:

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 values
    newImage.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. :slightly_smiling_face:

Happy coding!
Michael

1 Like

Valuable notes as always :grin:
Thank you so much

1 Like