1
I have a code that should receive the client’s Github username and generate a list with the name of its repositories. The list is generated, but always returns undefined
. The result would be something like <li>repositório 1</li>
and so on. The code is like this:
function add(){
var list = document.getElementById('list')
var user = document.getElementById('user')
var url = `https://api.github.com/users/${user.value}/repos`
axios.get(url)
.then(
function(response){
var repos = response.data
console.log(repos)
for(var item in repos){
item = document.createElement('li')
var textItem = document.createTextNode(repos.name)
item.appendChild(textItem)
list.appendChild(item)
}
}
)
.catch(
function(error){
console.log(error)
}
)
}
<input type="text" id="user" placeholder="Digite aqui seu nome de usuário">
<button onclick="add()">Adicionar repositórios</button>
<br>
<br>
<ul id="list">
</ul>
<script src="https://unpkg.com/axios/dist/axios.min.js"> </script>
<script src="main.js"></script>
I’m using Axios to make the request. Does anyone know where the problem is?
vlw for editing, first answer in stack!
– Diego Pereira