How to fix an issue with random images not showing?
09:34 27 Sep 2026

I'm having issues with the following piece of code https://codepen.io/jangerhofer/pen/OmLJyx I adapted (none of the images are showing when I run index.html):

index.html:

sketch.js:

function displayFour() {

  let images = [
    "p1.png",
    "p2.png",
    "p3.png",
    "p4.png",
    "p5.png"
]
 
  let selectedIndices = []

 while (selectedIndices.length < 4) {

    let index = images[Math.floor(Math.random() * images.length)]
 if (selectedIndices.indexOf(index) == -1) {

      selectedIndices.push(index)
    }
  }


  for (i = 0; i < selectedIndices.length; i++) {
    let img = document.createElement("img");
    img.src = selectedIndices[i]
    img.className = "image"

 
    let src = document.getElementById("images");
    src.appendChild(img);
  }
}

displayFour()

I'm getting issues on src.appendChild(img), but can't see what the problem is because I get the no debugger available error.

javascript image random