This assignment will teach you the following:
- AJAX Concepts
- How to use JavaScript to make AJAX requests
- Use AJAX callbacks to respond to server responses
- How to process JSON with JavaScript
Merge your pull request from the previous lesson (if you haven't already):
Fetch the updated instructions from the base repository:
Note: you may receive a conflict if you've made changes to the README or other instructions
Checkout your main branch and pull changes:
git checkout main
git pull
Create a new local branch to work on separate from the main branch:
git checkout -b lesson-6-1
Now, open the project directory in your code editor and continue to the next section.
- Open your
index.htmlfile - Below the "Skills" section, add a new
<section>element with anidattribute of value "projects" - Inside that element, create a level-two heading that says "Projects"
- After the heading, add an empty unordered list (
<ul>) element - Save and refresh your browser
- Open your
index.jsfile and start at the bottom - Create a new
XMLHttpRequestobject and store it in a variable namedgithubRequest - Call the
openmethod on yourgithubRequestobject and pass the necessary arguments- 1.
method: the method of your request (in this case, "GET") - 2.
url: the url of your request (in this case, "https://api.github.com/users/{GITHUB_USERNAME}/repos")
- 1.
- Finally, call the
sendmethod on yourgithubRequestobject to actually send the request - Save and refresh your browser
- You should see your XHR request in the DevTools "Network" tab (see screenshot)
Note: at this point, you have made a request to GitHub for your public repository data but nothing is being done with the data that is returned from the server
- Below the last line of code you just wrote, add a "load" event listener on your
githubRequestobject and pass the necessary arguments- 1.
event: the event that is being handled (in this case, "load") - 2.
callback: the function that runs when this event occurs
- 1.
- Inside the callback function you just created, parse the response and store it in a variable named
repositories- hint:
JSON.parse(this.response)
- hint:
- Log the value of
repositoriesin the console - Save and refresh your browser
- You should see your list of GitHub repositories logged in the console
Note: at this point, you have the response data but nothing is being displayed on the webpage itself
- Start below the line of code you just wrote
- Using "DOM Selection", select the #projects section by
idand store it in a variable namedprojectSection - Using "DOM Selection", query the
projectSection(instead of the entiredocument) to find the<ul>element and store it in a variable namedprojectList - Create a
forloop to iterate over yourrepositoriesArray, starting at index 0 - Inside the loop, create a new list item (
li) element and store it in a variable namedproject- hint:
createElementmethod
- hint:
- On the next line, set the inner text of your
projectvariable to the current Array element'snameproperty- hint: access the Array element using bracket notation
- On the next line, append the
projectelement to theprojectListelement- hint:
appendChildmethod
- hint:
- Save and refresh your browser
- You should see your list of repositories beneath the "Projects" heading
These tasks are entirely optional, but if you'd like a challenge then do your best to complete each item.
- (Optional) Transform your repository names into
<a>tags that link to GitHub (hint:html_urlproperty) - (Optional) Display additional information about your repositories (i.e. description, date, etc.)
- (Optional) Customize the styling of your "Projects" section list
Check the status of your local repository to double-check the changes you made:
git status
Stage the file(s) that you edited:
git add .
Check the status again and notice that the changes from before are now staged:
git status
Create a commit for the changes you made and add a message describing the changes you made:
Note: Replace
<message>with your message
git commit -m "<message>"
Push your commit to the remote repository (visible in GitHub):
git push
Check the log to make sure your commit has been published:
git log --oneline
Create a pull request and submit:
Created by Code the Dream

