Created
March 2, 2023 06:53
-
-
Save uzair004/b0b19ff91a21f69c1c7c566d2bc6cd55 to your computer and use it in GitHub Desktop.
Get random user profile pic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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