-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (31 loc) · 1.19 KB
/
script.js
File metadata and controls
41 lines (31 loc) · 1.19 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
let theform = document.querySelector('form');
let input = document.querySelector('input');
let img = document.querySelector('.profile-image');
let realname = document.querySelector('.username');
let myAbout = document.querySelector('.about');
let loader = document.querySelector('.loader');
let profile = document.querySelector('.profile');
theform.addEventListener('submit', getInfo);
function getInfo(e) {
e.preventDefault();
profile.classList.remove('change-them');
loader.classList.add('change-them');
if (!input.value){
input.value = 'Cannot be empty....!!!';
input.style.color = 'red';
setTimeout(() => input.value = '', 2000);
return;
}
makeCall(input.value)
input.value = ''
}
async function makeCall(username) {
let response = await fetch(`https://api.github.com/users/${username}`);
let theData = await response.json();
let [imageurl, thename,about] = [theData.avatar_url, '@'+theData.login, theData.bio];
img.src = imageurl;
realname.innerHTML = thename;
myAbout.innerHTML = about;
loader.classList.remove('change-them');
profile.classList.add('change-them')
}