Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 2 years ago

Consumo de API utilizando Fetch

angular, sass/scss, jquery
ERICKA•20
@erickalacantara
A solution to the Advice generator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


1 - Seleciona o botão com o ID "btn-gerar-conselho", o elemento de texto com o ID "conselho-texto" e o elemento de texto com o ID "idconselho" na página HTML.

2- Define uma função chamada "carregarConselho()" que é responsável por enviar uma solicitação à API "https://api.adviceslip.com/advice" usando o método "fetch".

3 - Quando a resposta da API é recebida, a função converte a resposta em um objeto JSON usando o método "response.json()", e atualiza o texto do elemento "conselhoTexto" com o conselho retornado pela API e o texto do elemento "idconselho" com o ID do conselho retornado.

4 - Adiciona um "listener" de evento que chama a função "carregarConselho()" quando a página é carregada ou quando o botão "btnGerarConselho" é clicado.

este script busca conselhos aleatórios da API e atualiza a página HTML com o conselho recebido.

Ps.: Me perdi no HTML, por incrível que pareça não consegui deixar o botão sobressaído como no designer

O que meu código pode melhorar?

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on ERICKA's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License