Hi everybody! 👋
This is a solution to the Advice generator app challenge on Frontend Mentor.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
Mobile Layout:
Desktop Layout:
- See hover states for all interactive elements on the page
- Generate a new piece of advice by clicking the dice icon
- Solution: Github Repository
- Solution: Github PAge
- Semantic HTML5 markup
- Flexbox
- Mobile-first workflow
- Sass - Css preprocessor
- Javascript
- Api/Json Files
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());
}
In the next challenges i would like to deep my knowledge about the handling of apis and its link whit html.
- Twitter/X - @agus_firpo
- Frontend Mentor - @Arfirpo
- Linkedin - Agustín Rodrigo Firpo