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 built with React

#react#fetch
Adriaan Bornmanβ€’ 60

@Cyber-Borries

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


Another great frontendmentor challenge done by Adriaan Bornman

For this challenge I chose to use React as a JavaScript framework

Something extra I added to the project is a loading section for the advice, I achieved this by conditionally rendering either "loading advice" or by rendering the response from the API

This whole challenge took me about an hour, the functionalibility (React) took about 10 - 15 mins to code up. I styled the app within about 15 mins, but making it responsive took me quite long

Thank you for looking at my solution, any feedback is welcome :)

Community feedback

Abdul Khalid πŸš€β€’ 72,160

@0xabdulkhalid

Posted

Hello there πŸ‘‹. Congratulations on successfully completing the challenge! πŸŽ‰

  • I have other recommendations regarding your code that I believe will be of great interest to you.

HTML 🏷️:

  • This solution generates accessibility error reports due to non-semantic markup, which lack landmark for a webpage
  • So fix it by replacing the element <div id="root"> the with semantic element <main> in your index.html file to improve accessibility and organization of your page.
  • What is meant by landmark ?, They used to define major sections of your page instead of relying on generic elements like <div> or <span>
  • They convey the structure of your page. For example, the <main> element should include all content directly related to the page's main idea, so there should only be one per page

HEADINGS ⚠️:

  • And, this solution had generated accessibility error report due to lack of level-one heading <h1>
  • Every site must want at least one h1 element identifying and describing the main content of the page.
  • An h1 heading provides an important navigation point for users of assistive technologies, allowing them to easily find the main content of the page.
  • So we want to add a level-one heading to improve accessibility by reading aloud the heading by screen readers, you can achieve this by adding a sr-only class to hide it from visual users (it will be useful for visually impaired users)

I hope you find this helpful πŸ˜„ Above all, the solution you submitted is great !

Happy coding!

Marked as helpful

1
P
Eileen dangeloβ€’ 1,600

@Eileenpk

Posted

Hi Adriaan! your project looks great, and I thought this might be a helpful tip.

Add error handling to your fetchAdvice function.

  const fetchAdvice = async () => {
    try {
      const response = await fetch("https://api.adviceslip.com/advice");
      const data = await response.json();
      setAdvice(data.slip);
    } catch (error) {
      console.error(error);
    }
  };

Here is a link that talks more about control flow and error handling.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling

Hope you found this helpful!

Marked as helpful

0

Adriaan Bornmanβ€’ 60

@Cyber-Borries

Posted

@Eileenpk Thank you! I thought about doing error handling (as it's the correct thing to do when working with APIs), but decided for such a simple API it won't be necessary, but thanks, I will implement it! :)

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