Quote Generator

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 lets two players compete in a 3×3 grid. It includes a simple interface, feedback on wins, and sound effects for added fun.

Read More »
Form & Input Handling

Text-to-Speech Converter

This Text-to-Speech app lets you type text and listen to it spoken aloud in different voices. Choose a voice, click ‘Listen,’ and hear the text in real-time.

Read More »