Commit c55c874f authored by GuilhemehliuG's avatar GuilhemehliuG
Browse files

feat : la possibilité de trouver une ville avec son code postal

parent 722d035b
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
const barreRechercheCodePostal = document.getElementById("codePostalInput");
const boutonRechercheCodePostal = document.getElementById("recherche");

let villes = [];

boutonRechercheCodePostal.addEventListener("click", onRechercher);

function onRechercher(){
@@ -23,3 +25,23 @@ function onRechercher(){
function onErreurDeSaisie(message){
    alert(message);
}

const setVilles = async codepostal => {
    return fetch("https://geo.api.gouv.fr/communes?codePostal="+codepostal)
    .then(res =>{
        if(!res.ok){
            throw new Error("gofuckyourself")
        }
        return res.json();
    })
    .then(data =>{
        villes = [];
        for(i = 0; i < data.length; i++){
            villes[i] = data[i].nom;
        }
    })
}

const getVilles = () => {
    return villes;
}
 No newline at end of file