09: Collaboration Activity - JSON Menu
Overview
This activity will have you demonstrate your understanding of the learning activities by applying the concepts to your home page. ♨️Work with your group to apply the following specifications to enhance your own, course home page which you will submit individually.
Instructions
This part of the assignment has you change your static activity links on your home page to a dynamic list of links using a JSON data source.
JSON Data
- Create a new folder named "
data
" within yourwdd230
root folder. - In that new
data
folder, create a new JSON file named "links.json
" - In the
links.json
file, add a single array of objects named "lessons
" - Add two properties to the first array object named "
lesson
" and "links
". - The
lesson
property value should contain the lesson number as a string written out like this: "01" - The
links
property contains an array of objects with two properties "url" and "title". - The
url
property value contains the relative address to the learning activity file. - The
title
property value contains a short descriptive name of the learning activity. - Add addition
lesson
array values in the same way for weeks 2 through 10.
Check Your Understanding - An Example
{
"lessons": [
{
"lesson": "02",
"links": [
{
"url":"lesson02/mediaquery.html",
"title":"Media Queries"
},
{
"url":"lesson02/design-principles.html",
"title":"Design Principles Document"
}
]
},
...
JavaScript - Build Link Menu Dynamically
Use JavaScript and this new JSON source file to replace the static activity links with dynamically built list.
The rendered activity and assignment links section will still look the
same. You
will replace all the content with a blank element, ready to be built with a list of lesson
numbers and their associated hyperlinks using JavaScript.
- In your
scripts
folder within thewdd230
root folder, add a new JavaScript file named "links.js
". - In the links.js file, create a
baseURL
variable that references your root wdd230 repository, GitHub pages URL.Example
const baseURL = "https://yourgithubusername.github.io/wdd230/";
- Next, add a variable named
linksURL
that references your links.json data file.Example
const linksURL = "https://yourgithubusername.github.io/wdd230/data/links.json";
- Write an asynchronous function to get the links data in the links.json data file.
- Test the JSON result by writing the data to the console. In order to test your
work at this point, you will need to write a line of code in links.js which calls the
getLinks() function. Once your are satisfied or producing links, remove the
console.log() statement.
Example
async function getLinks() { const response = await fetch(linksURL); const data = await response.json(); console.log(data); } getLinks();
- In the getLinks function, add a new line of code at the end that calls a function that
will build out the available activity links from the data response.
- Name the function displayLinks.
- Send the data as an argument.
Example
async function getLinks() { const response = await fetch(linksURL); const data = await response.json(); displayLinks(data); }
- Create the displayLinks() function and name the function's single parameter weeks. Remember from the json data that you wrote and tested that the data is an array of objects representing weeks of the term.
- Using your existing static HTML links structure in your index.html document as a guide,
use a loop to process each week using it's "week" string and "links' object ("url" and
"title") to create the output.
The latter-day prophets application in the learning activity provided you with an example to follow.
Testing
- Always practice good design and development techniques by adhering to the course development standards.
Submission
- Commit your local repository and push your work to your wdd230 GitHub Pages enabled repository on GitHub.
- Submit your home page URL in I-Learn.