Skip to content

Instantly share code, notes, and snippets.

@uzair004
Created March 2, 2023 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uzair004/b0b19ff91a21f69c1c7c566d2bc6cd55 to your computer and use it in GitHub Desktop.
Save uzair004/b0b19ff91a21f69c1c7c566d2bc6cd55 to your computer and use it in GitHub Desktop.
Get random user profile pic
const API_URL = "https://randomuser.me/api/";
fetch(API_URL)
.then((response) => response.json())
.then((data) => {
const imageUrl = data.results[0].picture.large;
const name = data.results[0].name.first + " " + data.results[0].name.last;
const img = document.createElement("img");
img.src = imageUrl;
img.alt = name;
document.body.appendChild(img);
})
.catch((error) => console.log(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment