+
Skip to content

efecollins/advice-app

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

Advice-App Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Media Query
  • Google Fonts
  • CSS Variables
  • Vanilla JavaScript
  • Fetch API

What I learned

When I began the challenge, I listed every language/tech to use for this project. I thought it would require stuffs like NodeJS, Express and the likes. So, I did a little digging and I figured that FOR SMALL PROJECTS, USE SMALL THINGS and this is the end result with only HTML, CSS & JavaScript.

CSS

For the dice button hover state, creating the glow effect was difficult and trickish for me and I was King Kong joyful when I did it. I am proud of this piece of code:

:root {
  --l_cyan: hsl(193, 38%, 86%);
  --n_green: hsl(150, 100%, 66%);
  --g_blue: hsl(217, 19%, 38%);
  --dg_blue: hsl(217, 19%, 24%);
  --d_blue: hsl(218, 23%, 16%);
}

.dice-bg:hover {
  box-shadow: 0px 0px 40px 0px var(--n_green);
  cursor: pointer;
}

JavaScript

This is my first time using the Fetch API for a GET request. I learnt APIs with NodeJS so this was tough. Cheers to Fetch API, Async and Await and Promises. I'm proud of you!

// store async function in a variable
const getAdvice = async () => {
    // get request through fetch
    const response = await fetch('https://api.adviceslip.com/advice');
    // parse json
    const adviceJSON = await response.json();
    // console.log(adviceJSON);
    document.querySelector('.id').innerHTML = adviceJSON.slip.id;
    document.querySelector('.quote').innerHTML = '"'+ adviceJSON.slip.advice +'"';
}

Continued development

In future projects, I'd love to know how to use jQuery to make get/post requests. See all my projects on Github.

Yeah, I'd also have to sharpen my knowledge of promises, asynchronous functions & callbacks, async & await and many more.

Useful resources

  • Flavio Copes JavaScript E-Book - This is Flavio Copes' website. You can find e-books on various subjects which includes JavaScript. His book helped me understand arrow functions together with the Fetch API. I really liked this pattern and will use it going forward.

  • Rapid API Guides - This is an amazing article which helped me finally understand Fetch API with Async-Await. I'd recommend it to anyone still learning this concept.

  • Dmitri Pavlutin - This article explains everything Fetch API from A-(Z)X. Not Z, because I have to improve.

Author

About

An advice web application that generates random advice. Enjoy!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载