-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (42 loc) · 1.4 KB
/
app.js
File metadata and controls
51 lines (42 loc) · 1.4 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
// select the elements:
const body = document.querySelector("#body");
const imgDIV = document.querySelector("#img");
const imgTag = document.querySelector("#imgTag");
const nameDIV = document.querySelector("#name");
const followersDIV = document.querySelector("#followers");
const personalDataDIV = document.querySelector("#personalData");
// page Load Event
// api now
const apiCall = function () {
const xhr = new XMLHttpRequest();
// const api = "https://api.github.com/users/hiteshchoudhary";
const api = "https://api.github.com/users/Rohitxkoli ";
xhr.open("GET", api);
let apiDATA = null;
xhr.onreadystatechange = function () {
console.log(xhr.readyState);
if (xhr.readyState === 4) {
const dataWithString = this.response;
// console.log(dataWithString);
const dataWithJson = JSON.parse(dataWithString);
console.log(typeof dataWithJson);
apiDATA = dataWithJson;
generateUI(apiDATA);
}
};
xhr.send();
};
const generateUI = function (api) {
console.log(api);
console.log("generateUI working");
// image add
imgTag.src = api.avatar_url;
//name add
nameDIV.innerHTML = `Name: ${api.name} ❤️`;
// followers add
followersDIV.innerHTML = `Github Followers: ${api.followers} ${
api.followers < 500 ? "📈" : "📉"
}`;
// about
personalDataDIV.innerHTML = `Bio: ${api.bio}`;
};