Skip to content

lucaslinyker/advice-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Advice generator app solution

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.

Table of contents

Overview

The challenge

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

Screenshot

Screenshot of the page

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • Mobile-first workflow
  • BEM - For arquiteture CSS

What I learned

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"
  }

Continued development

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.

Useful resources

  • Fetch api Mdn - This helped me to understand how to use the fetch API.

Author

⬆ Back to top

Releases

No releases published

Packages

 
 
 

Contributors