const API_URL = "https://swapi.dev/api/planets/?page="; let pageEnCours = 1; let tableau_perso = new Array(); // function pour afficher les planetes et leur correspondances async function getPlanets() { const PLANETS = await fetch(API_URL+pageEnCours); const PLANET = await PLANETS.json(); const total_pages = PLANET.count/PLANET.results.length; tableau_perso = []; // on vide le div document.getElementById('container').innerHTML = ""; // boucle pour parser les planetes for(i=0;i

${PLANET_NAME}

+

Rotation :

${ROTATION_PERIOD}

ORBITAL :

${ORBITAL_PERIOD}

Diameter :

${DIAMETER}

Climate :

${CLIMATE}

Gravity :

${GRAVITY}

Terrain :

${TERRAIN}

Surface water :

${SURFACE_WATER}

Population :

${POPULATION}

`; tableau_perso.push({name:PLANET_NAME,rotation:ROTATION_PERIOD,orbital:ORBITAL_PERIOD,diameter:DIAMETER,climate:CLIMATE,gravity:GRAVITY,terrain:TERRAIN,surface:SURFACE_WATER,population:POPULATION}); } const BUTTONS_FILMS = document.querySelectorAll('.films'); for(var i = 0;i < BUTTONS_FILMS.length;i++){ let BUTTON = BUTTONS_FILMS[i]; BUTTON.addEventListener("click", function() { //console.log(BUTTON.nextElementSibling); getFilms(BUTTON.value,BUTTON.nextElementSibling.id); }); } const BUTTONS_RESIDENTS = document.querySelectorAll('.residents'); for(var i = 0;i < BUTTONS_RESIDENTS.length;i++){ let BUTTON = BUTTONS_RESIDENTS[i]; BUTTON.addEventListener("click", function() { //console.log(BUTTON.nextElementSibling); getResidents(BUTTON.value,BUTTON.nextElementSibling.id); }); } const accordion = document.getElementsByClassName('etendre'); for (i=0; i${FILM.title}

`; } } // function pour afficher les résidents async function getResidents(liste,div) { const url = liste.split(','); console.log(div); document.getElementById(div).innerHTML = ""; for(i=0;i${RESIDENT.name}

`; } } // boucle pour afficher les boutons de navigation fetch(API_URL) .then(response => response.json()) .then(data => { let totalPages = data.count / data.results.length; for (let index = 1; index < totalPages +1; index++) { document.getElementById('buttons').innerHTML += ` `; } let buttons = document.querySelectorAll('.allButtons'); let boutonNum = document.querySelectorAll('.boutonNum'); console.log(boutonNum); for (let i = 0; i < buttons.length; i++) { buttons[i].addEventListener("click", function(e) { if (e.target.name === "moins" || e.target.name === "plus"){ pageEnCours = pageEnCours + parseInt(e.target.value); if(pageEnCours < 1){ pageEnCours = 1; }else if(pageEnCours > boutonNum.length){ pageEnCours = boutonNum.length; } }else{ pageEnCours = parseInt(e.target.value); } getPlanets(); }); }}); document.getElementById('myInput').addEventListener("keyup", function() { searchPeople(); }); function searchPeople() { // Declare variables let query = myInput.value; // if(query.length>1){ // getSearch(query); // }else{ // getPeople(); // } //console.log(tableau_perso); let results = tableau_perso.filter(user=>user.name.includes(query)); console.log(results); document.getElementById('container').innerHTML = ""; for(i=0;i

${results[i].name}

+

Rotation :

${results[i].rotation}

ORBITAL :

${results[i].orbital}

Diameter :

${results[i].diameter}

Climate :

${results[i].climate}

Gravity :

${results[i].gravity}

Terrain :

${results[i].terrain}

Surface water :

${results[i].surface}

Population :

${results[i].population}

`; const accordion = document.getElementsByClassName('etendre'); for (i=0; i