-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (30 loc) · 957 Bytes
/
script.js
File metadata and controls
40 lines (30 loc) · 957 Bytes
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
'use strict';
const baseURL = 'https://api.github.com/'
function displayResults(responseJson) {
console.log(responseJson);
$('#results-list').empty();
for(let i = 0; i < responseJson.length; i++){
$('#results-list').append(
`<li><p>"${responseJson[i].name}"</p></li>
<a href="${responseJson[i].html_url}">
${responseJson[i].html_url}</a>`
)
}
}
function getUsername(searchUser) {
const url = baseURL + `users/${searchUser}/repos`;
console.log(url);
fetch(url)
.then(response => response.json())
.then(responseJson => displayResults(responseJson))
.catch(error => console.log("Something went wrong!"))
}
function watchForm() {
$('form').submit(event => {
event.preventDefault();
const searchUser = $('#js-search-user').val();
getUsername(searchUser);
});
}
$(watchForm);
console.log("App is running, waiting for input");