Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Advice generator App Main

Agyemang99 140

@Agyemang99

Desktop design screenshot for the Advice generator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


What are you most proud of, and what would you do differently next time?

Made good use of Math. Random

What challenges did you encounter, and how did you overcome them?

How to I develop the API instead of using an array

What specific areas of your project would you like help with?

API

Community feedback

Luca 130

@LucaJahnen

Posted

Hello Agyemang99,

You can make API Calls in JavaScript using the fetch API like this:

const makeRequest = async () => {
  try {
    const url = "https://api.adviceslip.com/advice"
    const response = await fetch(url)
    const data = response.json()
    return data
 } catch (error) {
  // error handling
  console.log(error)
  }
}

// use the function to display the quote
const displayQuote = async () => {
  const advice = await makeRequest() 
document.querySelector("h1").textContent = advice.slip.advice
document.querySelector("p").textContent = advice.slip.id
}
displayQuote()

I am using async/await syntax. If you would like to know more about how it works I recommend this video.

Please mark this feedback as helpful if it was and let me know if you have further questions.

Happy Coding

Luca

0

Please log in to post a comment

Log in with GitHub
Discord logo

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