Skip to content

hellen17/advice-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 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

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Sass
  • JavaScript
  • Mobile-first workflow
  • Fetch API

What I learned

Fetch function makes the API request, which returns a Promise that resolves with the API response.

const getAdvice = () => {

fetch('https://api.adviceslip.com/advice')
    .then(response => {
        if (response.ok) {
            return response.json();
        } else {
            throw new Error('Something went wrong');
        }})
    .then(data => {
        console.log(data.slip)
        document.getElementById('advice-id').innerHTML = data.slip.id;
        document.getElementById('advice-text').innerHTML = `"${data.slip.advice}"`;
        }
    )
}
getAdvice();

Useful resources

Author

About

Frontend mentor challenge - Advice generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published