-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (33 loc) · 1.27 KB
/
script.js
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
let username="";
document.querySelector("form").addEventListener("submit",function(event) {
event.preventDefault();
username=document.getElementById("username").value;
//console.log(username);
let userdata= {
name:"",
email:"",
followers:0,
};
const baseUrl="https://api.github.com/users/";
const fullUrl=baseUrl+username;
// get user endpoint, then getting the response as json
const userDetails=fetch(fullUrl).then(res=>res.json())
// as json is our actual data check if we have the right data
.then(
data=>{
//console.log(data);
return ([data.avatar_url,data.login,data.name,data.followers,data.following]);
});
document.getElementById("userDetails").className="userDetails is-flex";
const getDetails=()=>{
userDetails.then((a)=>{
//console.log(a);
document.getElementById("userimage").src=a[0];
document.getElementById("username").innerHTML=`Username: ${a[1]}`;
document.getElementById("name").innerHTML=`Name: ${a[2]}`;
document.getElementById("followers").innerHTML=`Followers: ${a[3]}`;
document.getElementById("following").innerHTML=`Following: ${a[4]}`;
})
}
getDetails();
});