Skip to content

In this repo I use a free API key from API ninjas(Check them out on https://api-ninjas.com/) to generate random quotes on a simple web app.

License

Notifications You must be signed in to change notification settings

markuptitan/random_quotes_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

The Random Quotes Generator is a simple web application designed to provide users with random quotes from various categories. With just a click of a button, users can generate a new quote each time, making it a fun and engaging way to receive inspiration or insight.

The application features a user-friendly interface, and it fetches quotes from the API-Ninjas Quotes API. It is designed to be responsive, ensuring a seamless experience across different devices. Error handling is also implemented using SweetAlert2 to notify users in case of issues.

Whether you're looking for a quick motivational boost or simply enjoy interesting quotes, this tool offers a dynamic and interactive experience.

Features

  • Random Quote Generation: Fetches and displays a new random quote each time the user clicks the "Generate quote" button. Quotes are selected from various categories to ensure variety.

  • Category-Based Quotes: Quotes are categorized into a wide range of themes such as "happiness," "inspirational," "love," and more, allowing users to explore different types of quotes.

  • Responsive Design: The application is designed to be fully responsive, providing an optimal viewing experience on devices of all sizes, from desktops to mobile phones.

  • Error Handling: Utilizes SweetAlert2 to provide user-friendly error messages in case of any issues with fetching quotes or other operational problems.

  • Simple and Intuitive Interface: Features a clean and user-friendly interface with easy navigation and clear instructions, ensuring a pleasant user experience.

  • API Integration: Integrates with the API-Ninjas Quotes API to provide a wide variety of quotes with minimal setup and configuration.

Technologies Used

  • HTML: Provides the basic structure of the web application, including the layout and content.

  • CSS: Used for styling the application, including layout, colors, fonts, and responsive design. Utilizes rem and em units for a flexible and adaptive design.

  • JavaScript: Handles the dynamic aspects of the application, including fetching data from the API, updating the DOM, and managing user interactions.

  • Fetch API: Utilized for making network requests to the API-Ninjas Quotes API, allowing the application to retrieve and display quotes.

  • SweetAlert2: Integrated for displaying user-friendly and customizable error messages in case of issues with fetching quotes or other errors.

  • API-Ninjas Quotes API: Provides a source of diverse quotes categorized by various themes. The API is used to fetch quotes based on the selected category.

  • Responsive Design: Ensures that the application is usable and visually appealing across a range of devices, from desktops to mobile phones.

Getting Started

To get started with the Random Quotes Generator and serve it locally using npm http-server, follow these steps:

Prerequisites

  • Node.js: Ensure you have Node.js installed on your device. This will also install npm, the Node.js package manager.
  • Web Browser: Ensure you have a modern web browser (e.g., Chrome, Firefox, Safari) installed on your device.

Clone the Repository

  1. Clone the repository to your local machine using Git:

    git clone https://github.com/yourusername/random_quotes_generator.git
  2. Navigate to the project directory:

    cd random_quotes_generator

Install Dependencies

  1. Install http-server globally using npm if you haven't already:
    npm i -g http-server
  2. Start the local server:
    http-server .
  3. By default, http-server will serve your files on http://localhost:8080. Open this URL in your web browser to view the application.

Configuration

API Key

The application fetches quotes from the API-Ninjas Quotes API. To use your own API key, follow these steps:

  1. Obtain an API Key:

  2. Update the API Key in the Code:

    • Open the js/index.js file in your code editor.

    • Locate the line where the apiKey variable is defined:

      const apiKey = 'YOUR_API_KEY';
    • Replace 'YOUR_API_KEY' with the API key you obtained from API-Ninjas:

      const apiKey = 'your_actual_api_key_here';
  3. Save the Changes:

    • Save the changes to js/index.js.
  4. Test the Configuration:

    • Refresh the page or restart the local server to ensure that the updated API key is used.

Customization

You can also customize the application by adjusting the following settings:

  1. Categories:

    • The list of categories from which quotes are selected is defined in the categories array in js/index.js.

    • Add or remove categories based on your preferences:

      const categories = [
        'age', 'alone', 'amazing', 'anger', 'architecture', 'art', 'attitude',
        'beauty', 'best', 'birthday', 'business', 'car', 'change', 'communication',
        'computers', 'cool', 'courage', 'dad', 'dating', 'death', 'design', 'dreams',
        'education', 'environmental', 'equality', 'experience', 'failure', 'faith',
        'family', 'famous', 'fear', 'fitness', 'food', 'forgiveness', 'freedom',
        'friendship', 'funny', 'future', 'god', 'good', 'government', 'graduation',
        'great', 'happiness', 'health', 'history', 'home', 'hope', 'humor',
        'imagination', 'inspirational', 'intelligence', 'jealousy', 'knowledge',
        'leadership', 'learning', 'legal', 'life', 'love', 'marriage', 'medical',
        'men', 'mom', 'money', 'morning', 'movies', 'success'
      ];
  2. Styling:

    • Modify the css/styles.css file to change the appearance of the application. Adjust styles like font size, colors, padding, and margins according to your design preferences.
  3. Error Handling:

    • The application uses SweetAlert2 for error messages. Customize the alert styles and messages in js/index.js:

      Swal.fire({
        icon: 'error',
        title: 'Oops...',
        text: 'Something went wrong!',
        footer: 'Please try again later.'
      });

By following these steps, you can configure and customize the Random Quotes Generator to fit your needs.

Usage

  1. Load the Application:

    • After setting up and starting the server with http-server, open your web browser and navigate to http://localhost:8080 (or the URL provided by your server).
  2. Generate Quotes:

    • Click the "Generate quote" button to fetch and display a new random quote.
    • The application will display the quote and the author in the designated area on the page.
  3. Explore Categories:

    • The application fetches quotes from a random category each time you click the button.
    • You can customize the categories by modifying the categories array in the js/index.js file.
  4. Handle Errors:

    • If there are issues with fetching quotes or other errors, SweetAlert2 will display a user-friendly error message.
  5. Refresh the Page:

    • To generate a new quote without clicking the button, you can refresh the page.

Contact

For any questions, suggestions, or issues, please feel free to reach out:

Your feedback and contributions are welcome!

About

In this repo I use a free API key from API ninjas(Check them out on https://api-ninjas.com/) to generate random quotes on a simple web app.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published