Skip to content

Arfirpo/advice-generator-app-main

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hi everybody! 👋

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

Mobile Layout:

Mobile LAyout

Desktop Layout:

Desktop Layout

  • See hover states for all interactive elements on the page

  • Generate a new piece of advice by clicking the dice icon

Links 🔗

My process ⚙️

Built with 🛠️

  • Semantic HTML5 markup
  • Flexbox
  • Mobile-first workflow
  • Sass - Css preprocessor
  • Javascript
  • Api/Json Files

What I learned 📚

In this challenge i learned how to use an api (this time was the Advice slip API), how to manipulate it with javascript (using fetch, then & catch). Also i learned how to aplicate the math function to generate a random number

diceBtn.addEventListener('click', ()=>{
  //calling the created function below
    getAdvice();
});


function getAdvice(){
    //generate a random number
    const id = Math.floor(Math.random() * 100) + 1;
    //calling the api with the functions fetch & them
    fetch(`https://api.adviceslip.com/advice/${id}`)
    .then(res=>{
        return res.json()
    }).then(data =>{
    //show the api values in the html
        let adv = data.slip.advice;
        adviceTxt.innerHTML = `"${adv}"`;
        adviceId.innerHTML = `${id}`;
    })
    .catch(err => getAdvice()); 
}

Continued development 🔨

In the next challenges i would like to deep my knowledge about the handling of apis and its link whit html.

Author 🙋🏻‍♂️

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published