tp-figma-js/script.js

112 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-10-18 09:55:53 +00:00
/*const NOM = document.getElementsByClassName('nom');
const PRENOM = document.getElementsByClassName('prenom');
const IDENTIFIANT = document.getElementsByClassName('identifiant');
const EMAIL = document.getElementsByClassName('email');
const AVATAR = document.getElementsByClassName('avatar');*/
2021-10-17 15:49:02 +00:00
const MEMBER = document.getElementById('personne');
2021-10-18 10:12:11 +00:00
const BUTTON = document.getElementById('page2');
2021-10-18 11:04:33 +00:00
const BUTTON1 = document.getElementById('page1')
2021-10-18 10:12:11 +00:00
2021-10-18 09:55:53 +00:00
console.log(MEMBER);
2021-10-17 15:49:02 +00:00
const API_URL = "https://reqres.in/api/users?page=1";
fetch(API_URL)
.then((response) => {
console.log(response);
return response.json()
})
.then(responsFormat => {
console.log(responsFormat);
2021-10-18 08:44:35 +00:00
for(let index = 0; index <6; index++){
2021-10-18 08:59:45 +00:00
console.log(responsFormat.data[index]);
const PERSONNE = responsFormat.data[index];
2021-10-17 15:49:02 +00:00
console.log(PERSONNE);
2021-10-18 08:59:45 +00:00
MEMBER.innerHTML +=`
2021-10-18 09:55:53 +00:00
<div class = "fiche">
2021-10-18 09:20:00 +00:00
<img src="${PERSONNE.avatar}" alt="Photo d'identité">
2021-10-18 10:37:36 +00:00
<p class= "nom">${PERSONNE.last_name} ${PERSONNE.first_name}</p>
2021-10-18 10:34:36 +00:00
<!--<p class="prenom">${PERSONNE.first_name}</p>-->
2021-10-18 09:55:53 +00:00
<p class ="identifiant">${PERSONNE.id}</p>
<p class = "email">${PERSONNE.email}</p>
2021-10-18 08:59:45 +00:00
</div>
`
/* NOM.innerText = responsFormat.data[0].last_name;
PRENOM.innerText = responsFormat.data[0].first_name;
IDENTIFIANT.innerText = responsFormat.data[0].id;
EMAIL.innerText = responsFormat.data[0].email;
AVATAR.src = responsFormat.data[0].avatar;*/
}
2021-10-18 09:21:16 +00:00
BUTTON.addEventListener('click', ()=>{
const API_PAGE2 = "https://reqres.in/api/users?page=2";
fetch(API_PAGE2)
.then((response2) => {
console.log(response2);
return response2.json()
})
.then(responsFormat2 => {
console.log(responsFormat2);
MEMBER.innerHTML = " ";
2021-10-18 09:21:16 +00:00
for(let index = 0; index <6; index++){
console.log(responsFormat2.data[index]);
const PERSONNE = responsFormat2.data[index];
console.log(PERSONNE);
MEMBER.innerHTML +=`
2021-10-18 10:09:56 +00:00
<div class="fiche">
<img src="${PERSONNE.avatar}" alt="Photo d'identité">
2021-10-18 10:37:36 +00:00
<p class= "nom">${PERSONNE.last_name} ${PERSONNE.first_name}</p>
<!--<p class="prenom">${PERSONNE.first_name}</p>-->
2021-10-18 10:09:56 +00:00
<p class="identifiant">${PERSONNE.id}</p>
<p class="email">${PERSONNE.email}</p>
2021-10-18 09:21:16 +00:00
</div>
`
}
2021-10-18 09:23:34 +00:00
})
2021-10-18 09:21:16 +00:00
2021-10-17 15:49:02 +00:00
2021-10-18 11:04:33 +00:00
}
)
BUTTON1.addEventListener('click', ()=>{
const API_PAGE1 = "https://reqres.in/api/users?page=1";
fetch(API_PAGE1)
.then((response1) => {
console.log(response1);
return response1.json()
})
.then(responsFormat1 => {
console.log(responsFormat1);
MEMBER.innerHTML = " ";
for(let index = 0; index <6; index++){
console.log(responsFormat1.data[index]);
const PERSONNE = responsFormat1.data[index];
console.log(PERSONNE);
MEMBER.innerHTML +=`
<div class="fiche">
<img src="${PERSONNE.avatar}" alt="Photo d'identité">
<p class= "nom">${PERSONNE.last_name} ${PERSONNE.first_name}</p>
<!--<p class="prenom">${PERSONNE.first_name}</p>-->
<p class="identifiant">${PERSONNE.id}</p>
<p class="email">${PERSONNE.email}</p>
</div>
`
}
}
)
2021-10-17 15:49:02 +00:00
}
2021-10-18 08:59:45 +00:00
)
2021-10-17 15:49:02 +00:00
.catch(err => {
console.error(err);
2021-10-18 09:21:16 +00:00
})
2021-10-17 15:49:02 +00:00
});