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
- See hover states for all interactive elements on the page
- Generate a new piece of advice by clicking the dice icon
- Solution URL: frontendmentor.io/solutions/advice-generator-app-BannXvzEy7
- Live Site URL: acyein.github.io/advice-generator-app
- HTML
- Tailwind CSS
- JavaScript
Figuring out how to show / hide loading spinner before / after data is fetched from API.
function getAdvice() {
// before fetching: show loader, hide quote el, disable btn
loader.style.display = 'block';
quoteEl.style.display = 'none';
btn.disabled = true;
fetch(url)
.then(response => {
return response.json();
})
.then(data => {
// take id & advice from json
let id = data.slip.id;
let advice = data.slip.advice;
// once fetched: hide loader, show quote el, make btn clickable
loader.style.display = 'none';
quoteEl.style.display = 'block';
btn.disabled = false;
// set id & advice into elements
adviceId.innerHTML = id;
quoteEl.innerHTML = advice;
})
.catch(function(error) {
console.log(error);
});
}- Pure CSS Loaders - Spinning loaders made only with CSS.
- Website - Chian Yein
- Frontend Mentor - @acyein
