Skip to content

Commit

Permalink
update activities
Browse files Browse the repository at this point in the history
  • Loading branch information
vwolfley committed Mar 4, 2024
1 parent fd06c22 commit fcbe0ce
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ <h3>Learning Activities</h3>
</li>
<li>Lesson 07: <a href="lesson07/lazyload.html">Lazy Loading</a> | <a href="lesson07/bom.html">Local Storage</a></li>
<li>Lesson 08: <a href="lesson08/tablebuild.html">Table Build</a> | <a href="lesson08/form-start/index.html">Form Build</a></li>
<li>Lesson 09: <a href="lesson09/new-ward-members.json">JSON File</a> | <a href="/lesson09/prophets.html">Fetch API</a></li>
<li>Lesson 10: </li>
<li>Lesson 11: </li>
<li>Lesson 09: </li>
<li>Lesson 12: </li>
<li>Lesson 13: </li>
<li>Lesson 14: </li>
Expand Down
91 changes: 91 additions & 0 deletions lesson09/new-ward-members.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"wardInfo": {
"familyName": "Wolfley",
"moveInDate": "2002-04-12",
"numberOfPeople": 7,
"visitedByBishopric": true,
"familyMembers": [
{
"name": "Vern Wolfley",
"gender": "Male",
"birthdate": "1973-04-01"
},
{
"name": "Kindy Wolfley",
"gender": "Female",
"birthdate": "1975-11-10"
},
{
"name": "Elena Wolfley",
"gender": "Female",
"birthdate": "2001-09-03"
},
{
"name": "Natalie Wolfley",
"gender": "Female",
"birthdate": "2003-08-27"
},
{
"name": "Meghan Wolfley",
"gender": "Female",
"birthdate": "2005-08-10"
},
{
"name": "Vern Wolfley",
"gender": "Male",
"birthdate": "2007-04-18"
},
{
"name": "Benjamin Wolfley",
"gender": "Male",
"birthdate": "2008-10-05"
}
]
},
"familyName": "Sherwood",
"moveInDate": "2004-05-11",
"numberOfPeople": 8,
"visitedByBishopric": true,
"familyMembers": [
{
"name": "Bill Sherwood",
"gender": "Male",
"birthdate": "1966-04-01"
},
{
"name": "Kathy Sherwood",
"gender": "Female",
"birthdate": "1969-11-10"
},
{
"name": "Kimberly Sherwood",
"gender": "Female",
"birthdate": "2081-09-03"
},
{
"name": "Kris Sherwood",
"gender": "Female",
"birthdate": "2083-08-27"
},
{
"name": "Koni Sherwood",
"gender": "Female",
"birthdate": "2085-08-10"
},
{
"name": "Jeff Sherwood",
"gender": "Male",
"birthdate": "2087-04-18"
},
{
"name": "Greg Sherwood",
"gender": "Male",
"birthdate": "2089-10-05"
},
{
"name": "Katie Sherwood",
"gender": "Female",
"birthdate": "2091-10-05"
}
]
}
22 changes: 22 additions & 0 deletions lesson09/prophets.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Latter-Day Prophets</title>
<link rel="stylesheet" href="styles/normalize.css" />
<link rel="stylesheet" href="styles/prophets.css" />
</head>
<body>
<header>
<h1>Latter-day Prophets</h1>
</header>
<main>
<div id="cards"></div>
</main>
<footer>
Vern Wolfley | Latter-day Prophets
</footer>
<script src="scripts/prophets.js"></script>
</body>
</html>
61 changes: 61 additions & 0 deletions lesson09/scripts/prophets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const url = "https://brotherblazzard.github.io/canvas-content/latter-day-prophets.json";
const cards = document.querySelector("#cards");

async function getProphetData() {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error("Failed to fetch data");
}
const data = await response.json();
// console.table(data);
displayProphets(data.prophets);
return data;
} catch (error) {
console.error("Error fetching data:", error);
throw error;
}
}

getProphetData();

const displayProphets = (prophets) => {
console.log(prophets);
prophets.forEach((prophet) => {
// Create a section element and store it in a variable named card
const card = document.createElement("section");
// Create an h2 element and store it in a variable named "fullName"
const fullName = document.createElement("h2");
// Create a p element and store it in a variable named "birthdate"
const birthdate = document.createElement("p");
// Create a p element and store it in a variable named "birthplace"
const birthplace = document.createElement("p");
// Create an img element and store it in a variable named "portrait"
const portrait = document.createElement("img");

// Populate the heading element with the prophet's full name using a template string
fullName.textContent = `${prophet.name} ${prophet.lastname}`;

// Populate the paragraph element with the prophet's birthdate using a template string
birthdate.textContent = `Date of Birth: ${prophet.birthdate}`;

// Populate the paragraph element with the prophet's birthplace using a template string
birthplace.textContent = `Place of Birth: ${prophet.birthplace}`;

// Build the image element by setting attributes
portrait.setAttribute("src", prophet.imageurl);
portrait.setAttribute("alt", prophet.fullName);
portrait.setAttribute("loading", "lazy");
portrait.setAttribute("width", "200");
portrait.setAttribute("height", "300");

card.appendChild(fullName);
card.appendChild(birthdate);
card.appendChild(birthplace);
card.appendChild(portrait);

// add the section card to the "cards" div
cards.appendChild(card);
});
};

Loading

0 comments on commit fcbe0ce

Please sign in to comment.