Skip to content

Instantly share code, notes, and snippets.

@LaeLita
Created March 17, 2023 06:49
Show Gist options
  • Save LaeLita/3cb56fed6a279257407816370e1434fa to your computer and use it in GitHub Desktop.
Save LaeLita/3cb56fed6a279257407816370e1434fa to your computer and use it in GitHub Desktop.
VwGdxLM
<html>
<head>
<title>Random Pondpony Generator</title>
<link rel="stylesheet" href="assets/stylesheets/app.css">
</head>
<body>
<header class="flex">
<h1>Random Pondpony Generator</h1>
<button>Generate Random Pond</button>
</header>
<section class="flex">
<img src="">
</section>
<script src="assets/scripts/app.js"></script>
</body>
</html>
const imageArray = [
"https://f2.toyhou.se/file/f2-toyhou-se/images/47129656_OX75mvp2LlHxhgD.jpg",
"https://f2.toyhou.se/file/f2-toyhou-se/images/58142838_7BrTdgtIkzi5f2G.png",
"https://f2.toyhou.se/file/f2-toyhou-se/images/58142267_1Itp9xjFdHDxRQi.png"
];
const image = document.querySelector("img");
const button = document.querySelector("button");
window.onload = () => generateRandomPicture(imageArray);
button.addEventListener("click", () => generateRandomPicture(imageArray));
function generateRandomPicture(array){
let randomNum = Math.floor(Math.random() * array.length);
image.setAttribute("src", array[randomNum]);
}
html, body {
margin: 0;
height: 100%;
width: 100%;
}
header {
width: 100%;
padding-bottom: 25px;
flex-direction: column;
}
img {
width: 70%;
}
.flex {
display: flex;
justify-content: center;
align-items: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment