I have completed the “Image gallery” test, and I would like to get the evaluation.
Thank you in advance
Test link : https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Image_gallery .
Code link: https://codepen.io/someone_49/pen/dyzmmJY .
mikoMK
(Michael Koch)
November 6, 2021, 11:30pm
2
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
1 Like
Valuable notes as always
Thank you so much
1 Like