Quote Generator

Table of Contents

Technologies used -
Description

This Quote Generator provides a new, motivational quote with each click. Perfect for daily inspiration, users can easily view random quotes along with their authors, or instantly share favorites on Twitter.

Fetches Quotes: The getQuote function uses fetch() to retrieve a random quote from the API and display it

.Displays Content: Updates the inner HTML of the quote and author elements to display the current quote.

Twitter Sharing: The tweet function opens a new window, pre-filled with the quote text and author for easy sharing on Twitter.

Highlighted Source Code
				
					const quote = document.getElementById("quote");
const author = document.getElementById("author");

const api_url = "https://dummyjson.com/quotes/random";

// Function to fetch and display a new quote
async function getQuote(url) {
    const response = await fetch(url);
    const data = await response.json();
    console.log(data);
    quote.innerHTML = data.quote;
    author.innerHTML = data.author;
}

getQuote(api_url); // Load the first quote

// Function to share the quote on Twitter
function tweet() {
    window.open(
        "https://twitter.com/intent/tweet?text=" + quote.innerHTML + " --by " + author.innerHTML, 
        "Tweet Window", 
        "width=600, height=300"
    );
}
				
			

Related Projects

Fun Project

Tic Tac Toe Game

The Interactive Tic Tac Toe Game is a classic two-player game implemented using HTML, CSS, and JavaScript. This engaging application

Read More »