5
I’m starting in Javascript and I’m having the following difficulty, I need to take a variable and access it in another Function.
I have created a variable without specifying anything making it global, but it did not work here, using the console returns as undefined
.
I need to take what returns from "axios.get()
" be the .then
or .catch
and access it in btnElement.onclick = function ()
.
var inputElement = document.querySelector('input');
var btnElement = document.querySelector('button');
var listElement = document.querySelector('.div lista');
btnElement.onclick = function () {
var listItemElement = document.createElement('ul');
pegarRepositorio();
// QUERO USAR O "RESPONSE" AQUI
};
function pegarRepositorio() {
var inputValue = inputElement.value;
axios.get(`https://api.github.com/users/${inputValue}/repos`)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.warn('Erro 404 - Usuário não encontrado');
});
};
Good afternoon Augusto, show, worked out here. Just one question, I need to return on the screen, if the user is typed wrong, must be returned error 404... so . then/. catch, how do I keep them?
– Rafael Simionato
@Rafaelsimionato I made an edition in the reply and see if it meets your expectations.
– Augusto Vasques