-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.js
More file actions
28 lines (25 loc) · 933 Bytes
/
Script.js
File metadata and controls
28 lines (25 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const imagem = document.querySelector('img');
const botao = document.querySelector('#botao');
const nomeDoPersonagem = document.querySelector('#nome');
const especie = document.querySelector('#especie');
const condicao = document.querySelector('#status');
gerarValorAleatorio = () => {
return Math.floor(Math.random() * 671);
}
pegarPersonagem = () => {
let numeroAleatorio = gerarValorAleatorio();
return fetch(`https://rickandmortyapi.com/api/character/${numeroAleatorio}`, {
method: 'GET',
headers: {
Accept: 'application/json',
"Content-type": 'application/json'
}
}).then((response) => response.json()).then((data) => {
imagem.src= data.image;
imagem.alt= data.name;
nomeDoPersonagem.innerHTML = data.name;
especie.innerHTML = data.species;
condicao.innerHTML = data.status;
});
}
botao.onclick = pegarPersonagem;