0

/** Crear un script que consuma La Api https://api.got.show/api/

  • Listar 10 personajes aleatorios con los campos Titulo, Nombre y casa.
  • los datos deben ser mostrados de esta manera " Ser Addam Marbrand, House Marbrand"
  • Mostrar datos consumidos en la consola
  • puede usar fetch o axios*/

hasta ahora tengo esto y no se como seleccionar solo 10 personajes aleatorios, ya que si ejecuto me salen todos los personajes en un lista

button.addEventListener('click', () => {
    axios({
        method: 'GET',
        url: 'https://api.got.show/api/show/characters'
    }).then(res => {
        const list = document.getElementById('list')
        const fragment = document.createDocumentFragment()
        for (const userInfo of res.data) {
            const listItem = document.createElement('LI')
            listItem.textContent = `Ser ${userInfo.name} de la casa ${userInfo.house} y soy el ${userInfo.titles} `
            fragment.appendChild(listItem)
        }
        list.appendChild(fragment)
    }).catch(err => console.log(err))
})
<!DOCTYPE html>
<html lang="es">

<head>
  <meta charset="UTF-8" />
  <title>axios</title>
</head>

<body>
  <h1 id="title">Axios - Get</h1>
  <button id="button">Get Data</button>
  <ul id="list"></ul>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script src="https://api.got.show/api/show/characters"></script>
  <script src="Api.js"></script>
</body>

</html>

4

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.