-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,62 @@ | ||
async function sprintChallenge5() { // Note the async keyword, in case you wish to use `await` inside sprintChallenge5 | ||
// π WORK WORK BELOW THIS LINE π | ||
async function sprintChallenge5() { // Note the async keyword so you can use `await` inside sprintChallenge5 | ||
// π WORK ONLY BELOW THIS LINE π | ||
// π WORK ONLY BELOW THIS LINE π | ||
// π WORK ONLY BELOW THIS LINE π | ||
|
||
const { data: learners } = await axios.get('http://localhost:3003/api/learners') | ||
const { data: mentors } = await axios.get('http://localhost:3003/api/mentors') | ||
// π ==================== TASK 1 START ==================== π | ||
|
||
// π§ Use Axios to GET learners and mentors. | ||
// β Use the variables `mentors` and `learners` to store the data. | ||
// β Use the await keyword when using axios. | ||
|
||
let mentors = [] // fix this | ||
let learners = [] // fix this | ||
|
||
// π ==================== TASK 1 END ====================== π | ||
|
||
// π ==================== TASK 2 START ==================== π | ||
|
||
// π§ Combine learners and mentors. | ||
// β At this point the learner objects only have the mentors' IDs. | ||
// β Fix the `learners` array so that each learner ends up with this exact structure: | ||
// { | ||
// id: 6, | ||
// fullName: "Bob Johnson", | ||
// email: "[email protected]", | ||
// mentors: [ | ||
// "Bill Gates", | ||
// "Grace Hopper" | ||
// ]` | ||
// } | ||
|
||
// π ==================== TASK 2 END ====================== π | ||
|
||
const cardsContainer = document.querySelector('.cards') | ||
const info = document.querySelector('.info') | ||
info.textContent = 'No learner is selected' | ||
|
||
for (let learner of learners) { | ||
const mentorIds = learner.mentors | ||
const mentorNames = [] | ||
for (let id of mentorIds) { | ||
for (let mentor of mentors) { | ||
if (id === mentor.id) mentorNames.push(`${mentor.firstName} ${mentor.lastName}`) | ||
} | ||
} | ||
learner.mentors = mentorNames | ||
} | ||
|
||
const cardsContainer = document.querySelector('.cards') | ||
// π ==================== TASK 3 START ==================== π | ||
|
||
for (let learner of learners) { // looping over each learner object | ||
|
||
// π§ Flesh out the elements that describe each learner | ||
// β Give the elements below their (initial) classes, textContent and proper nesting. | ||
// β Also, loop over the mentors inside the learner object, creating an <li> element. | ||
// β Fill each <li> with a mentor name, and append it to the <ul> mentorList. | ||
// β Inspect the mock site closely to understand what the initial texts and classes look like! | ||
|
||
for (let learner of learners) { | ||
const card = document.createElement('div') | ||
card.classList.add('card') | ||
const heading = document.createElement('h3') | ||
heading.textContent = learner.fullName | ||
card.appendChild(heading) | ||
const email = document.createElement('div') | ||
email.textContent = learner.email | ||
card.appendChild(email) | ||
const mentorsHeading = document.createElement('h4') | ||
mentorsHeading.classList = 'closed' | ||
mentorsHeading.textContent = 'Mentors' | ||
card.appendChild(mentorsHeading) | ||
const mentorsList = document.createElement('ul') | ||
for (let mentorName of learner.mentors) { | ||
const li = document.createElement('li') | ||
li.textContent = mentorName | ||
mentorsList.appendChild(li) | ||
} | ||
|
||
// π ==================== TASK 3 END ====================== π | ||
|
||
// π WORK ONLY ABOVE THIS LINE π | ||
// π WORK ONLY ABOVE THIS LINE π | ||
// π WORK ONLY ABOVE THIS LINE π | ||
card.appendChild(mentorsList) | ||
card.dataset.fullName = learner.fullName | ||
cardsContainer.appendChild(card) | ||
|
@@ -83,10 +101,8 @@ async function sprintChallenge5() { // Note the async keyword, in case you wish | |
const footer = document.querySelector('footer') | ||
const currentYear = new Date().getFullYear() | ||
footer.textContent = `Β© BLOOM INSTITUTE OF TECHNOLOGY ${currentYear}` | ||
|
||
// π WORK WORK ABOVE THIS LINE π | ||
} | ||
|
||
// β DO NOT CHANGE THE CODE BELOW | ||
// β DO NOT CHANGE THIS CODE. WORK ONLY INSIDE TASKS 1, 2, 3 | ||
if (typeof module !== 'undefined' && module.exports) module.exports = { sprintChallenge5 } | ||
else sprintChallenge5() |