Skip to content

Commit

Permalink
Merge pull request #193 from Mefisto04/mefisto
Browse files Browse the repository at this point in the history
Create Avatar Generator Webpage
  • Loading branch information
Swpn0neel authored Oct 14, 2023
2 parents 473af6f + 4b7e3d1 commit eb0a236
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Avatar Generator/avatar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
text-align: center;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

h1 {
margin-bottom: 20px;
}

#userCards {
display: flex;
flex-wrap: wrap;
justify-content: center;
}

.userCard {
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
margin: 10px;
width: 200px;
text-align: center;
}

.userAvatar {
border-radius: 50%;
width: 80px;
height: 80px;
margin-bottom: 10px;
}
</style>
<title>Random User Cards</title>
</head>
<body>
<div class="container">
<h1>Random User Cards</h1>
<div id="userCards"></div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
const userCardsContainer = document.getElementById('userCards');

function generateUserCards(numCards) {
for (let i = 0; i < numCards; i++) {
fetch('https://randomuser.me/api/')
.then(response => response.json())
.then(data => {
const user = data.results[0];
const name = `${user.name.first} ${user.name.last}`;
const experience = `Experience : ${user.dob.age-20}`;
const city = user.location.city;
const avatar = user.picture.medium;

const userCard = document.createElement('div');
userCard.classList.add('userCard');
userCard.innerHTML = `
<img src="${avatar}" alt="User Avatar" class="userAvatar">
<h2>${name}</h2>
<p>${experience}</p>
<p>${city}</p>
`;

userCardsContainer.appendChild(userCard);
})
.catch(error => console.error('Error fetching random user:', error));
}
}

// Generate a specified number of user cards (e.g., 5)
generateUserCards(10);
});
</script>
</body>
</html>

0 comments on commit eb0a236

Please sign in to comment.