-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (40 loc) · 1.35 KB
/
script.js
File metadata and controls
52 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const apiusers = 'https://api.github.com/users/';
const searchval = document.getElementById("search");
const searchbtn = document.getElementById("btn");
const main = document.getElementById("main");
const form = document.getElementById("form");
async function getUser(user){
const response = await fetch(apiusers + user);
const responsedata = await response.json();
console.log(responsedata );
createUserCard(responsedata);
}
//to display user details
function createUserCard(user){
const cardData = `
<div>
<img class="avatar" src="${user.avatar_url}" alt="${user.name}" />
</div>
<div>
<h2>${user.name}</h2>
<p>${user.bio}</p>
<ul class="info">
<li>${user.followers}<strong>~Followers</strong></li>
<li>${user.following}<strong>~Following</strong></li>
<li>${user.public_repos}<strong>~Repos</strong></li>
</ul>
`;
main.innerHTML = cardData;
firstName = user.name;
if(user.name == null ){
main.innerHTML="Oops!! User Not Found!!";
}
}
searchbtn.addEventListener("click", (e) => {
e.preventDefault();
const user = searchval.value;
if (user) {
getUser(user);
searchval.value = "";
}
});