I very new to Javascript and I'm attempting to create multiple modal images within one page. I generate this coding below
// create references to the modal...
var modal = document.getElementById('myModal');
// to all images
 var images = document.getElementsByClassName('visual');
  // the image in the modal
 var modalImg = document.getElementById("img01");
 // Go through all of the images with our custom class
 for (var i = 0; i < images.length; i++) {
  var img = images[i];
  // and attach our click listener for this image.
  img.onclick = function (evt) {
console.log(evt);
modal.style.display = "block";
modalImg.src = this.src;
 }
}
 // When the user clicks anywhere outside of the modal, close it
 window.onclick = function(event) {
   if (event.target == modal) {
       modal.style.display = "none";
   }
}
It states that line 12 "Dont make functions within loops". Would appreciate help in solving this issue.
 
    