Skip to content

Commit 5a17b58

Browse files
committed
added project
1 parent e99385c commit 5a17b58

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

10_github-profile/index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<script src="https://cdn.tailwindcss.com"></script>
88
</head>
99
<body>
10-
10+
<div class="container">
11+
<h1>GitHub Profile Viewer</h1>
12+
<form id="profileForm">
13+
<input type="text" id="username" placeholder="Enter GitHub username" required>
14+
<button type="submit">Search</button>
15+
</form>
16+
<div id="profileContainer" class="profile"></div>
17+
</div>
18+
19+
<script src="script.js"></script>
1120
</body>
1221
</html>

10_github-profile/script.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
document.getElementById('profileForm').addEventListener('submit', function(event) {
2+
event.preventDefault();
3+
const username = document.getElementById('username').value;
4+
fetchGitHubProfile(username);
5+
});
6+
7+
async function fetchGitHubProfile(username) {
8+
const profileContainer = document.getElementById('profileContainer');
9+
profileContainer.innerHTML = '';
10+
11+
try {
12+
const response = await fetch(`https://api.github.com/users/${username}`);
13+
if (!response.ok) throw new Error('Profile not found');
14+
15+
const profileData = await response.json();
16+
displayProfile(profileData);
17+
} catch (error) {
18+
profileContainer.innerHTML = `<p>${error.message}</p>`;
19+
}
20+
}
21+
22+
function displayProfile(profile) {
23+
const profileHTML = `
24+
<img src="${profile.avatar_url}" alt="Avatar" class="avatar">
25+
<div class="profile-info">
26+
<h2>${profile.name}</h2>
27+
<p><strong>Username:</strong> ${profile.login}</p>
28+
<p><strong>Followers:</strong> ${profile.followers}</p>
29+
<p><strong>Following:</strong> ${profile.following}</p>
30+
<p><strong>Public Repos:</strong> ${profile.public_repos}</p>
31+
<a href="${profile.html_url}" target="_blank">Visit Profile</a>
32+
</div>
33+
`;
34+
document.getElementById('profileContainer').innerHTML = profileHTML;
35+
}

0 commit comments

Comments
 (0)