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

Advice generator app with (HTML,CSS,JS)

Raed Alnan•160
@raedalnan
A solution to the Advice generator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I have a problem dealing with api like every time I call the generate function ,return with the same advice .

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ivan•2,610
    @isprutfromua
    Posted over 3 years ago

    Hi there. You did a good job 😎

    keep improving your programming skills🛠️

    your solution looks great, however, if you want to improve it, you can follow these recommendation:

    				**HTML**
    

    ✅ Use HTML5 semantic elements. Make sure correct use of the HTML5 semantic elements like: header, footer, main, nav, article, section. It’s will help you to write more structured piece of code.

    ✅ Set a meaningful img alt attribute. It’s best practice for SEO purpose.

    ✅ Avoid complex wrapping. For better performance please tried to avoid unnecessary wrapping. It will create unnecessary node in your HTML tree and reduce performance too.

       <h2>"<span id="advice"></span>"</h2>
        <div class="divider">
          <img src="images/pattern-divider-desktop.svg" alt="">
        </div>
        <div class="dice">
          <button class="click">
            <img src="images/icon-dice.svg"  alt="dice-icon">
          </button>
        </div>
    

    ✅ Write Code Comments. It’s best practice to write human-readable code. Tried to comment your block of code. It will help you or any other developer to refactor the piece of code blocks.

    ✅ **Use only one <h1> element for one code sheet **. It is important to avoid using more than one <h1> element for one code sheet. Having only one <h1> element on a web page is vital for Search Engine Optimization (SEO). It helps search engines understand what a web page is all about (the main idea of a web page).

    ✅ Do not use divs to create headers and footers – use semantic elements instead. It's advisable to use the <figure> element when adding captions to your images. It is important to use the <figcaption> element along with the <figure> element for it to work.

    				**CSS**
    

    ✅ Use a CSS reset . By default, browsers don’t apply the same default styling to HTML elements, a CSS reset will ensure that all element have no particular style. For example: css-reset

    ✅ Write consistent CSS. At the beginning part of the project you can set some rules for maintain throughout to your entire stylesheet. If you follow the convention or BEM, you’ll be able to write CSS without being afraid of side effects.

    ✅ Don’t use @import . The @import directive is much slower than the other way to include stylesheets into a html document:

    <link rel='stylesheet' type='text/css' href='a.css'>
    <link rel='stylesheet' type='text/css' href='font.css'>
    

    ✅ Avoid Extra Selectors. Adding extra selectors won't bring Armageddon or anything of the sort, but they do keep your CSS from being as simple and clean as possible.

    ✅ Use Clamp . The clamp function make smaller and simple CSS to control element width.

    width: clamp(100px, 50%, 300px);
    

    ✅ Use CSS Variables . Making the code flexible is equally important so that refactoring won’t be a problem for you. One of the best ways to achieve this is variables.

    I hope my feedback will be helpful. You can mark it as useful if so 👍 it is not difficult for you, but I understand that my efforts have been appreciated

    Good luck and fun coding 🤝⌨️

    Marked as helpful
  • Marija H.•110
    @mh1251
    Posted over 3 years ago

    I checked the live version of the exercise, it returns a new quote everytime i click on the button and it works :)) good job!

    Also i wanted to comment about your commented out part (with fetch) of the app.js file. The code would work like that also, if you didn't store everything in the obj variable. In the obj variable you should store the data you retrieve from the fetch and then use it. Instead you should do it like this:

    async function adviceGen(){
    let obj = await fetch("https://api.adviceslip.com/advice") .then(res => res.json())
    
     // It returns a promise by default, so you wont need the 'return' in front of res.json() 
     // Now the data is stored in the obj variable, and we wait for the promise inside the fetch(with async/await) and now you can use it do the following:
    
      id.innerText = obj.slip.id ;
      advice.innerText = obj.slip.advice ;
    }
    
    

    so your function should work likes this:

    async function adviceGen(){
      let obj = await fetch("https://api.adviceslip.com/advice") .then(res => res.json())
      id.innerText = obj.slip.id ;
      advice.innerText = obj.slip.advice ;
    }
    

    I hope this will help you also with further exercises, fetch is easier to use in my opinion so it will come in handy :)!!

    Marked as helpful

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
Frontend Mentor logo

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

Frontend Mentor

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

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

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub