@@ -41,30 +41,47 @@ function requestUserRepos(username) {
41
41
while ( root . firstChild ) {
42
42
root . removeChild ( root . firstChild ) ;
43
43
}
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" ) {
48
45
let ul = document . getElementById ( 'userRepos' ) ;
49
46
50
47
// Create variable that will create li's to be added to ul
51
48
let li = document . createElement ( 'li' ) ;
52
49
53
50
// Add Bootstrap list item class to each li
54
51
li . classList . add ( 'list-group-item' )
55
-
56
- // Create the html markup for each li
52
+ // Create the html markup for each li
57
53
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 = ( `
58
74
<p><strong>Repo:</strong> ${ data [ i ] . name } </p>
59
75
<p><strong>Description:</strong> ${ data [ i ] . description } </p>
60
76
<p><strong>URL:</strong> <a href="${ data [ i ] . html_url } ">${ data [ i ] . html_url } </a></p>
61
77
` ) ;
62
78
63
- // Append each li to the ul
64
- ul . appendChild ( li ) ;
79
+ // Append each li to the ul
80
+ ul . appendChild ( li ) ;
65
81
66
- }
82
+ }
67
83
84
+ }
68
85
}
69
86
70
87
// Send the request to the server
0 commit comments