mercredi 4 août 2021

how to display the same image from random image api

I am trying to generate a random image from Unsplash API. I would like to display the same image when I'm trying to open a webpage only when I'm using the same browser. Is there a way that this is possible?

here's my code.

function renderImage() {
let url = "https://api.unsplash.com/photos/random?client_id";
let imageElement = document.querySelector("#unsplashImage");

fetch(URL)
  .then((response) => response.json())
  .then((jsonData) => {
   imageElement.src = jsonData.urls.regular;
})
.catch((err) => {
  console.log("Error: " + err);
});
}

renderImage();



Aucun commentaire:

Enregistrer un commentaire