Skip to content

acyein/advice-generator-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Advice generator app solution

This is a solution to the Advice generator app challenge on Frontend Mentor.

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

Preview

Preview of advice generator app

Links

My process

Built with

  • HTML
  • Tailwind CSS
  • JavaScript

What I learned

Figuring out how to show / hide loading spinner before / after data is fetched from API.

function getAdvice() {
    // before fetching: show loader, hide quote el, disable btn
    loader.style.display = 'block';
    quoteEl.style.display = 'none';
    btn.disabled = true;

    fetch(url)
        .then(response => {
            return response.json();
        })
        .then(data => {
            // take id & advice from json
            let id = data.slip.id;
            let advice = data.slip.advice;
            
            // once fetched: hide loader, show quote el, make btn clickable
            loader.style.display = 'none';
            quoteEl.style.display = 'block';
            btn.disabled = false;

            // set id & advice into elements
            adviceId.innerHTML = id;
            quoteEl.innerHTML = advice;
        })
        .catch(function(error) {
            console.log(error);
        });
}

Useful resources

Author

About

An app that generates advice from a JSON API.

Topics

Resources

Stars

Watchers

Forks

Contributors