Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonathandavidpollock/ac8f7311aa6e02413f8b105e0294cb7f to your computer and use it in GitHub Desktop.
Save jonathandavidpollock/ac8f7311aa6e02413f8b105e0294cb7f to your computer and use it in GitHub Desktop.
window.onload = () => {
console.log('Inside the JS function');
// find the image elements
let imgArray = document.querySelectorAll('.random_image');
console.log(`Found all of these images: ${imgArray}`)
// Randomly pick a number
// Locate the image based off Random Number
const num = Math.floor(Math.random()*imgArray.length);
const imageToDisplay = imgArray[num];
console.log(`We choose this number for the random image: ${num}`);
console.log(`${imageToDisplay}`);
// He the image that are not the image chosen
for(let i = 0; i <= imgArray.length; i++){
if(i !== num) {
imgArray[i].remove();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment