This is a solution to the Advice generator app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Generate a new piece of advice by clicking the dice icon
- Solution URL: https://github.com/lucaslinyker/advice-generator
- Live Site URL: https://lucaslinyker.github.io/advice-generator/
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- Mobile-first workflow
- BEM - For arquiteture CSS
I learned how to use the fetch API to get data from an external API. I also learned how to handle errors.
Below you can see the code:
try {
const response = await fetch(apiURL);
if (!response.ok) {
throw new Error(`Error ${response.status} in the request!`);
}
const data = await response.json();
codeAdvice.innerText = data.slip.id;
textAdvice.innerText = `"${data.slip.advice}"`;
} catch (error) {
console.error(error);
codeAdvice.innerText = error.message;
textAdvice.innerText = "Try again!";
codeAdvice.style.color = "red"
textAdvice.style.color = "red"
}I want to continue learning about the fetch API and how to handle errors. I also want to learn more about the async/await and promises.
- Fetch api Mdn - This helped me to understand how to use the fetch API.
- GitHub - lucaslinyker
- Frontend Mentor - @lucaslinyker
- Instagram - @lucas_linyker
