Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladrillo committed May 6, 2024
1 parent 39e50f8 commit 9c4e698
Showing 1 changed file with 48 additions and 32 deletions.
80 changes: 48 additions & 32 deletions frontend/index.js
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)
Expand Down Expand Up @@ -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()

0 comments on commit 9c4e698

Please sign in to comment.