Skip to content

Commit d48f5d7

Browse files
committed
added corrections for corner cases
1 parent 02e44f0 commit d48f5d7

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

app.js

+26-9
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,47 @@ function requestUserRepos(username) {
4141
while (root.firstChild) {
4242
root.removeChild(root.firstChild);
4343
}
44-
// Loop over each object in data array
45-
for (let i in data) {
46-
47-
// Get the ul with id of of userRepos
44+
if (data.message === "Not Found") {
4845
let ul = document.getElementById('userRepos');
4946

5047
// Create variable that will create li's to be added to ul
5148
let li = document.createElement('li');
5249

5350
// Add Bootstrap list item class to each li
5451
li.classList.add('list-group-item')
55-
56-
// Create the html markup for each li
52+
// Create the html markup for each li
5753
li.innerHTML = (`
54+
<p><strong>No account exists with username:</strong> ${username}</p>`);
55+
// Append each li to the ul
56+
ul.appendChild(li);
57+
} else {
58+
59+
// Get the ul with id of of userRepos
60+
let ul = document.getElementById('userRepos');
61+
let p = document.createElement('p');
62+
p.innerHTML = (`<p><strong>Number of Public Repos:${data.length}</p>`)
63+
ul.appendChild(p);
64+
// Loop over each object in data array
65+
for (let i in data) {
66+
// Create variable that will create li's to be added to ul
67+
let li = document.createElement('li');
68+
69+
// Add Bootstrap list item class to each li
70+
li.classList.add('list-group-item')
71+
72+
// Create the html markup for each li
73+
li.innerHTML = (`
5874
<p><strong>Repo:</strong> ${data[i].name}</p>
5975
<p><strong>Description:</strong> ${data[i].description}</p>
6076
<p><strong>URL:</strong> <a href="${data[i].html_url}">${data[i].html_url}</a></p>
6177
`);
6278

63-
// Append each li to the ul
64-
ul.appendChild(li);
79+
// Append each li to the ul
80+
ul.appendChild(li);
6581

66-
}
82+
}
6783

84+
}
6885
}
6986

7087
// Send the request to the server
File renamed without changes.

0 commit comments

Comments
 (0)