vivian-mca / quote-generator

A generator that randomly pulls quotes from a Quotes API | Built with HTML, CUBE CSS methodology, and vanilla JavaScript
https://vivian-mca.github.io/quote-generator/
0 stars 0 forks source link
async-await cube-css cube-css-methodology fetch-api html html-css-javascript javascript

desktop design

Quote Generator

Live Demo

Solution for a challenge from zerotomastery.io.


Table of contents

Overview

About

This is a generator that randomly pulls quotes from a Quotes API.

Users should be able to:

  1. View the optimal layout for the app depending on their device's screen size.
  2. See hover states for all interactive elements on the page
  3. Generate a new quote by clicking the New Quote button.
  4. Pre-populate a Tweet with the generated quote by clicking the Twitter button.

Screenshot

Mobile design

mobile design

My process

Built with

What I learned

This was my first-time building a project using fetch API with async/await.

const getQuote = async () => {
  const apiUrl = "https://type.fit/api/quotes";
  try {
    const response = await fetch(apiUrl);
    apiQuotes = await response.json();
    newQuote();
  } catch (error) {
    alert(`Whoops, something went wrong. Try again later.`);
    console.log(error);
  }
};

With this challenge, I learned how to solve CORS issues by building a proxy server. Fortunately, the API I used for the final product did not have this issue.

Another first-time encounter I had while creating this project was using Twitter's Tweet Web Intent Docs to pre-populate a Tweet with the generated quote (code snippet below).

const tweetQuote = () => {
  const twitterUrl = `https://twitter.com/intent/tweet?text=${quoteText.textContent} - ${authorText.textContent}`;
  // Opens twitter page in new tab
  window.open(twitterUrl, "_blank");
};

Overall, this project was a great learning experience and made me feel slightly more confident utilizing async/await.

Continued development

Other ideas for this project include:

Useful resources

Acknowledgments