This enhanced version of the "Curious Cats Facts" application includes additional features such as the ability to add fun facts to a favorites list, play sound effects, and use animations and local storage to enhance the user experience.
Interactive Interface:
- A button that generates fun facts.
- Button to add fun facts to a favorites list.
- Reset button to hide the current messages.
Favorites:
- Ability to save fun facts to favorites using
localStorage. - Dedicated button to view stored favorites.
Animations:
- Fade-in and fade-out effects to improve message transitions.
Sound Effects:
- Plays a sound when clicking the start button.
Error Handling:
- Displays a generic error message if the API fails.
- HTML5: Basic structure of the project.
- CSS3: Animations and styling.
- JavaScript (ES6+): Interactive logic, DOM manipulation, and local storage.
- External API: Connects to
https://uselessfacts.jsph.pl/to fetch fun facts.
- When the page loads, the start button is ready to listen for click events.
- When clicking Start🐈⬛👽:
- A sound effect is played.
- A fade-in transition occurs.
- The previous content in the message container is cleared.
- The API is called to fetch a new fun fact.
- The message is displayed on the screen with a fade-in effect.
- When clicking the Add to Favorites button:
- The current fun fact is saved to a favorites array.
- The array is stored in
localStorageto persist between sessions.
- The View Favorites button redirects the user to another page to explore the saved fun facts.
- The Reset button clears the message container and hides the corresponding section.
- Clone the repository or download the files.
- Make sure you have a local environment set up to serve HTML files, such as Visual Studio Code with Live Server.
- Open the
index.htmlfile in a web browser. - Click the interactive buttons to explore the features:
- Start: Generates fun facts.
- Add to Favorites: Saves facts to favorites.
- View Favorites: Redirects to the favorites page.
index.html: Main structure of the page.styles/welcome.cssandstyles/facts.css: Interface and animation styles.src/js/apiService.js: Logic for interacting with the external API.src/js/events.js: Event handling and local storage management.
The API returns fun facts in JSON format:
{
"id": "random_id",
"text": "Cats sleep for 70% of their lives.",
"source": "https://example.com",
"language": "en",
"permalink": "https://uselessfacts.jsph.pl/random_id"
}