Design comparison
SolutionDesign
Solution retrospective
Hi everybody! 👋
This is a solution to the Advice generator app challenge on Frontend Mentor.
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
Links 🔗
- Solution: Github Repository
- Solution: Github PAge
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 🙋🏻♂️
- Twitter/X - @agus_firpo
- Frontend Mentor - @Arfirpo
- Linkedin - Agustín Rodrigo Firpo
Community feedback
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord