I’m not talking about displaying Github’s content on screen, so according to the exercise, someone will help me?

Asked

Viewed 66 times

-2

/*Create a screen with one that should be named after a user on Github. After typing the user name and click the search button the application should search for the Github API (as per URL below) the user repositories data and show them on screen: Example URL: https://api.github.com/users/diego3g/repos Just change "diego3g" by user name. Add After filling in the input and adding, the following list should appear below:

  • repo1
  • repos2
  • repos 3
  • repos4
  • repos5

*/

<meta charset="UTF-8">
<title>Curso Java Script</title>

<div id="app">

    <input type = "text" name = "user"/>
    <button onclick="adicionar()">Adicionar</button>
    <ul>
        <li></li>
    </ul>

</div>

<script src="https://unpkg.com/axios/dist/axios.js"></script>
<script src="exercicio2.js"></script>

var receivedInput = Document.querySelector('#app input'); var booBotao = Document.querySelector('#app button'); var booUl = Document.querySelector('#app ul');

Function fill(fill in){

var login2 = recebeInput.value;

for(repositorio of preenchimento){

    var elementoT = document.createTextNode(repositorio.login2);
    elementoL = document.createElement('li');

    elementoL.appendChild(elementoT);
    recebeUl.appendChild(elementoL);
}

}

Function storageSite(login){

if(!login) return;

axios.get('https://api.github.com/users/' + login + '/repos')
.then(function(response){

    preenchimento(response.data);
})
.catch(function(error){

    console.log('Deu erro');
})

}

Function add(){

var login = recebeInput.value;
console.log(login);

var requisicao = new XMLHttpRequest();
requisicao.open('GET', 'https://api.github.com/users/' + login + '/repos');
requisicao.send(null);

requisicao.onreadystatechange = function(){

    if(requisicao.readyState === 4){

        if(requisicao.status === 200){

            armazenandoSite(login);

            }

        else{

            console.log('Algo deu errado');

            }

        }

    }
}
  • Where is an error message? What is the message?

  • Error like this does not think it is logical error because it is not pulling the data to be printable on screen.

1 answer

0

Your problem is that the tag <script> is not closed. You have to have <script></script>. Plus you can simplify the code and do something like this:

var userInput = document.querySelector('#app input[name="user"]');
var ul = document.querySelector('#app ul');

function preenchimento(dados) {
  for (repositorio of dados) {
    const li = document.createElement('li');
    li.innerHTML = repositorio.description;
    ul.appendChild(li);
  }
}

function adicionar() {
  const user = userInput.value;
  const url = 'https://api.github.com/users/' + user + '/repos';
  axios.get(url)
    .then((response) => preenchimento(response.data))
    .catch((error) => {
      console.log('Deu erro a buscar', url);
      console.log('Erro:', error);
    });
}
<script src="https://unpkg.com/axios/dist/axios.js"></script>

<div id="app">
  <input type="text" name="user" />
  <button onclick="adicionar()" type="button">Adicionar</button>
  <ul></ul>
</div>

  • But they are closed: <script src="https://unpkg.com/axios/dist/axios.js"></script> <script src="exercicio2.js"></script> Or can I declaim 2 scripts like this? It is because most of the code is in another file a . js

  • It was much more simplified anyway.

  • And it worked really well, testing here, but I left the script the way it is, and I fixed what was different, but I thought I pulled all the information from the file but it’s good, thanks, now I’m going to the next challenge using this basis.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.